r/unity_tutorials • u/twitcheddd • 1d ago
Text How I made a UI Toolkit screen react to music (write-up with code)
I wrote up how I made a music player screen in UI Toolkit react to the song. The parts that carry over to other projects:
- Reducing the spectrum to two signals: a beat (the bass jumping well above its running average, with a short cooldown) and a loudness level that rises fast and falls slowly.
- Giving the two signals separate properties (loudness sets the scale, beats add a short MoveY or an additive nudge) so they never cancel each other out.
- Replacing a looping rotation with a "motor": one speed value that you tween for start-up, braking and scratch recovery, so the spin never hiccups at the loop point.
- Why dragging lagged a frame behind the mouse: I was reading the angle back from the resolved style, which is one frame stale.
- What breaks in a WebGL build (no spectrum data, no negative pitch, no mixer filters) and the fallbacks I used.
Playable in the browser (click once for sound): https://twitchedd.itch.io/cascade-audio-studio
Disclosure: the tweens use Cascade, a UI Toolkit animation library I make. The techniques work with any tween code.