Skip to main content

Spring animations for reactive Unity UI

A spring follows a reactive getter. Bind its output directly where the value type matches, or transform it with a getter.

var target = UI.Source(0f);
var spring = UI.Spring(() => target.Value, period: 0.5);
var frame = UI.Frame(UI.Position(() =>
new UnityEngine.Vector2(spring.Value, 0)));
target.Value = 200f;

Build this in a stable root/mount. The runtime host advances unscaled time automatically. Period is seconds; damping ratio 1 is critically damped and smaller ratios allow overshoot.

For reactive tuning:

var period = UI.Source(0.5);
var damping = UI.Source(1.0);
var spring = UI.Spring(() => target.Value,
period: period, dampingRatio: damping);

Control(position: ..., velocity: ..., impulse: ...) changes motion state for the next clock update. Assigning spring.Value publishes an immediate jump and clears velocity; the existing target remains active.

The solver advances at fixed 1/120 second substeps and settled springs unregister from clock updates.

UI.Step(deltaTime) selects manual time for the runtime session. Keep stepping springs, delayed exits and polled observations; the session continues using manual time. For valid input ranges and packed Unity types, see the animation API.

Run the spring animation example in Unity.