StepUtils
Utility functions primarily used to bind animations into update loops of the Roblox engine.
Functions
getAnimationStepSignal
Returns the signal animation should step on: RunService.RenderStepped on the client, RunService.Stepped (the physics pre-step) on a running server so that writes land before the physics step -- springs that drive CFrames stay in lockstep with constraints, characters, and replication. Heartbeat is only the fallback for a non-running DataModel (headless test runs, edit mode), where Stepped never fires.
Use this instead of hand-rolling the realm branch at call sites.
CAUTION
The argument shape is realm-dependent: RenderStepped fires (deltaTime) but Stepped fires
(time, deltaTime). Shared code connecting directly to this signal must not assume the
first argument is deltaTime.
getSteppedSignal
Returns the signal per-frame bookkeeping should run on: RunService.Stepped (the physics pre-step) on a running DataModel, falling back to RunService.Heartbeat on a non-running one (headless test runs, edit mode) where Stepped never fires.
Unlike StepUtils.getAnimationStepSignal this does not branch to RenderStepped on the client, so both realms step at the same point in the frame. Prefer it for work that is not driving visuals -- rescoring, polling, cache invalidation -- and that would otherwise silently stop running outside a live game.
CAUTION
Stepped fires (time, deltaTime) but Heartbeat fires (deltaTime). Do not assume the first
argument is deltaTime when connecting directly to this signal.
bindToRenderStep
StepUtils.bindToRenderStep(update: () → boolean--
should return true while it needs to update
) → ((...) → (),--
Connect function
() → ()--
Disconnect function
)Binds the given update function to StepUtils.getAnimationStepSignal.
local spring = Spring.new(0)
local maid = Maid.new()
local startAnimation, maid._stopAnimation = StepUtils.bindToRenderStep(function()
local animating, position = SpringUtils.animating(spring)
print(position)
return animating
end)
spring.t = 1
startAnimation()
TIP
Be sure to call the disconnect function when cleaning up, otherwise you may memory leak.
deferWait
StepUtils.deferWait() → ()Yields until the frame deferral is done
bindToStepped
StepUtils.bindToStepped(update: () → boolean--
should return true while it needs to update
) → ((...) → (),--
Connect function
() → ()--
Disconnect function
)Binds the given update function to RunService.Stepped. See StepUtils.bindToRenderStep for details.
TIP
Be sure to call the disconnect function when cleaning up, otherwise you may memory leak.
bindToSignal
StepUtils.bindToSignal(update: () → boolean--
should return true while it needs to update
) → ((...) → (),--
Connect function
() → ()--
Disconnect function
)Binds an update event to a signal until the update function stops returning a truthy value.
onceAtRenderPriority
StepUtils.onceAtRenderPriority(priority: number,func: function--
Function to call
) → function--
Call this function to cancel call
Calls the function once at the given priority level, unless the cancel callback is invoked.
onceAtStepped
This was deprecated in 3.5.2
StepUtils.onceAtStepped(func: function--
Function to call
) → function--
Call this function to cancel call
Invokes the function once at stepped, unless the cancel callback is called.
-- Sometimes you need to defer the execution of code to make physics happy
maid:GiveTask(StepUtils.onceAtStepped(function()
part.CFrame = CFrame.new(0, 0, )
end))
TIP
use RunService.Stepped:Once() instead
onceAtRenderStepped
This was deprecated in 3.5.2
StepUtils.onceAtRenderStepped(func: function--
Function to call
) → function--
Call this function to cancel call
Invokes the function once at renderstepped, unless the cancel callback is called.
TIP
use RunService.RenderStepped:Once() instead
onceAtEvent
This was deprecated in 3.5.2
StepUtils.onceAtEvent(func: function--
Function to call
) → function--
Call this function to cancel call
Invokes the function once at the given event, unless the cancel callback is called.