Lua ScriptingIntermediate

Animation playback API

Play, blend, stop, speed up, pause, and reverse existing animation clips.

Discover available clips

local names = gameObject.getAnimationNames()
for index, name in ipairs(names) do
    print(index .. ": " .. name)
end

Clip names are case-sensitive and come from the model file.

Play and stop

SignatureBehavior
playAnimation(name, loop?, blendTime?)Returns true when the clip exists. Defaults: loop=true, blendTime=0.2 seconds.
stopAnimation(name?, fadeOutTime?)Stops one clip or every clip. Default fade-out is immediate.
isAnimationPlaying(name?)Checks one clip or any active clip.

Control playback speed and direction

setAnimationSpeed(speed, name?) accepts a playback multiplier. Use 1 for normal speed, 0.5 for half speed, 0 to pause, and a negative value to play backward.

Pass a clip name to change only that animation action. If you omit name, the speed is applied to the object's animation mixer and affects every animation on the object. The named form is usually the safer choice while blending locomotion clips.

local walkClip = "walk"

function init()
    gameObject.playAnimation(walkClip, true, 0.2)
end

function update(deltaTime)
    local playbackSpeed = 1.0
    if input.moveBackward then
        playbackSpeed = -1.0
    end

    -- Target only the walk clip so blends and idle remain forward.
    gameObject.setAnimationSpeed(playbackSpeed, walkClip)
end

Do not restart every frame

playAnimation() resets the action to the beginning. Call it only when animation state changes; change speed per frame with setAnimationSpeed().

Reverse-playback limitation

Negative speed works directly for looping clips and reverses an already-playing action from its current playhead. A non-looping action started with playAnimation(name, false) begins at time zero, so it cannot start backward from the final frame with the current API.

Automatic locomotion

enableAutoAnimation(config) selects idle, walk, run, and jump clips from velocity and ground state. Call updateAutoAnimation() each frame. Use disableAutoAnimation() to stop it and getAnimationState() to inspect the current state.