Method UseFrame
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
UseFrame(Action<float>, int)
Per-frame callback: onFrame runs once per frame with the elapsed time in
seconds while the component stays mounted, and stops on unmount. The latest render's closure
is always the one invoked — a re-render swaps the callback without re-subscribing — so
per-frame data flows without touching component state (the escape hatch for
simulation-driven visuals; setting state per frame would re-render the world every tick).
Frames tick while the component's host is attached to a panel and pause while it is not. The elapsed
time is measured on the mount's MotionClock, and a frame over which that
clock did not move invokes nothing.
priority orders callbacks within the SAME panel — lower runs earlier,
equal priorities run in subscription (mount) order, and this stays true across a keyed
reorder of the host. A positive priority also takes rendering over, as in react-three-fiber:
while the host is attached, a SceneView(Camera?, string?, string?, string?, float, StyleOverrides?, Func<VisualElement, Action>?, string?, string?, string?, IReadOnlyDictionary<string, string>?, IReadOnlyDictionary<string, string>?, FiberEventBinding[]?) showing its camera in the same panel
holds that camera disabled, and the callback renders it with Camera.Render(). The
latest render's priority applies live, the same way onFrame
does — changing it does not restart the subscription or move it among same-priority siblings.
public static void UseFrame(Action<float> onFrame, int priority = 0)
Parameters
onFrameAction<float>Invoked once per frame with the elapsed time in seconds (always positive).
priorityintLower runs earlier within the same panel this frame. Defaults to 0.