Lua ScriptingIntermediate

Animation playback API

Play, blend, stop, speed up, pause, and reverse clips, drive locomotion automatically, and use the clips the default character ships with.

Runtime room configuration. The authority can call multiplayer.setAnimationConfig(objectId, config) to change locomotion clips on every screen. It replaces the whole bounded room-animation configuration (maximum 2048 UTF-8 JSON bytes). Precedence is runtime override, authored room animation, then legacy owner-recorded/default behavior. An empty table selects defaults; false suspends locomotion updates without stopping the current clip; nil clears the override. State speeds and the shared mixer rate default to 1. Prediction and presentation cannot write it: control scripts guard with multiplayer.isHost(). Only live canonical characters with a slot/control assignment are accepted; prop-only NPCs are excluded. Late join and reconnect receive the current override; it ends with the object, scene or run. Layers keep playing, and hand-back resumes the latest override or fallback. Existing gameObject animation calls are not automatically replicated. See Character animation in a room.

Discover available clips

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

Clip names are case-sensitive. They come from the model file, and from any external animations attached to the object.

External animations

A character or mesh can borrow clips from other files. In its inspector, click Add Animation, choose an FBX or glTF animation asset, and give it a Clip Name; scripts then play it by that name, exactly like a clip inside the model. An external clip is downloaded the first time a script plays it, not when the scene loads, so that first playAnimation call returns false and the clip starts a moment later. getAnimationNames() lists external clips before they have loaded. To have a clip ready before its first play, start loading it with preloadAnimations (see "Load clips ahead of time and move the playhead" below).

An added clip replaces the model's clip of the same name. If the model already has a clip called, say, crouch_walk and you add an animation with the Clip Name crouch_walk, the added file is the one that plays everywhere: from scripts, in automatic locomotion, on other players' screens in a multiplayer room, and as the length an animation timeline runs on. Use this to swap a model's built-in motion for a better one without renaming anything in your scripts. (Before 20 October 2026 the model's own clip kept playing while the inspector showed the added clip's length.) Only a clip added from another file replaces anything; an added entry that points at the model's own file does not.

Mixamo motions work on any Mixamo character. Every Mixamo character shares one skeleton, so a motion downloaded for one of them (Y Bot, say) plays on any other: you do not need to download each motion again for each character. As the clip loads, its bones are matched to the model's, even on the characters that number their bone prefix (mixamorig1, mixamorig2 and so on), and its hip height is scaled to the model's, so a shorter or taller character neither floats nor sinks. A character with very different proportions, such as a large creature, can still look slightly off at the feet and knees; for those, download the motions you use for that character.

What plays before a script does

A model with animations starts playing one as soon as it loads. Current Animation in the inspector (animationClipName) chooses which. Left at None, the model's first clip with a non-zero duration plays, which skips the empty "Take 001" stack some Mixamo exports carry. Animation Speed (animationSpeed) and Loop Animation (loopAnimation) apply to that clip. The first playAnimation or enableAutoAnimation from a script replaces it.

Root motion

A character's clips play in place. The engine removes the horizontal movement of the skeleton's root bone (the hips, on a Mixamo rig), pinning it to the model's rest pose, so the model stays centred on its physics capsule, which your script moves. Vertical movement is kept, so a death, crouch or roll clip lowers the body to the floor. To move the character across the ground during a clip, move it from the script.

This applies to the clips inside the model and to clips added with Add Animation. It applies to characters only: a mesh plays its clips' root motion as authored. The inspector's animation preview plays clips unfiltered, so it can show drift that the running game does not.

Play and stop

SignatureBehavior
playAnimation(name, loop?, blendTime?)Returns true when the clip started. Defaults: loop=true, blendTime=0.2 seconds. The first call for an external animation that has not loaded yet returns false and starts the clip once its file arrives.
stopAnimation(name?, fadeOutTime?)Stops one clip or every clip. Default fade-out is immediate. Animation layers keep playing; stop them with stopAnimationLayer.
releaseAnimation()In a multiplayer room, hands a character that a camera, GUI or presentation script took over with playAnimation or stopAnimation back to the engine's automatic locomotion on that browser, using the latest runtime override when set, then the character's authored room animation or legacy fallback. Safe to call repeatedly. Does nothing in single player, Preview outside a room, or a character's own control script. See Character animation in a room.
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, its animation layers included. The named form is usually the safer choice while blending locomotion clips.

Clips also follow the scene's time scale, on top of their own speed. When a scene script slows the game with scene.setTimeScale, every clip and automatic locomotion slows with it, and onAnimationFinished arrives correspondingly later in real time; at a scale of 0 every clip holds its pose. See Time scale and slow motion.

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

playAnimation replaces the object's base animation: every other clip it or locomotion played fades out over blendTime, or stops at once when blendTime is 0. It leaves animation layers alone. To play an upper-body clip on top of a walk, use a layer (see Animation layers below).

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.

Load clips ahead of time and move the playhead

An external clip loads the first time it is played or preloaded. Start the download early so the first play is not lost, and check that a clip has arrived before you rely on its timing.

SignatureBehavior
preloadAnimations(names?)Starts loading clips without playing them: one name, a list of names, or with no argument every clip the object has. Returns true when all of them had already loaded; poll isAnimationReady or areAnimationsLoaded for the rest.
isAnimationReady(name)True once the clip has loaded, so playing or seeking it takes effect at once.
areAnimationsLoaded()True once every clip getAnimationNames() lists has loaded.
seekAnimation(name, time)Moves a playing clip's playhead to time seconds, clamped to its length, and poses the model at once, so a bone read straight afterwards sees the new pose. Returns false when the clip has not loaded or is not playing: play it first. A finished one-shot seeked back before its end plays on from there.
getAnimationTime(name?)The clip's playhead in seconds. With no name, the playhead of the clip posing the model most. nil when that clip is not playing.
getAnimationDuration(name)The clip's length in seconds; nil until it has loaded.

Know when a one-shot clip ends

Define onAnimationFinished(name) in the object's script and it is called once, with the clip's name, when a clip played with loop=false reaches its end. It runs after the frame's animation update rather than in the middle of it, and only once init() has run. Looping clips never finish.

local ATTACK = "attack"
local swinging = false

function init()
    -- Start the download now, so the first swing is not lost.
    gameObject.preloadAnimations({ ATTACK })
end

function update(deltaTime)
    if input.primaryFire and not swinging and gameObject.isAnimationReady(ATTACK) then
        swinging = true
        gameObject.playAnimation(ATTACK, false, 0.1)
    end
end

function onAnimationFinished(name)
    if name == ATTACK then
        swinging = false
    end
end

Use the playhead, not a timer, to find a moment inside a clip: getAnimationTime(ATTACK) / getAnimationDuration(ATTACK) is how far through the swing the character is, and stays right if the clip's speed changes.

Animation markers and timelines

A marker is a named moment in a clip, such as the frame a foot touches the ball. Add markers under Animation Markers in a character's, mesh's or ragdoll's inspector: pick the clip, click Add Marker, then give each marker a name and a time in seconds from the start of the clip. A name may repeat within a clip, for example left_touch twice in a dribble cycle. An object can carry up to 256 markers.

A timeline is a clip's clock, driven by your script rather than by the drawn animation. Because it uses only the clip's recorded length and its markers, which are both saved with the game, it runs the same everywhere: in Preview, in a published single-player game, on a multiplayer room's server and in a player's predicted copy.

local DRIBBLE = "Forward Jog Dribbling Soccer Ball"

function init()
    gameObject.playAnimationTimeline(DRIBBLE) -- loops by default
end

function onAnimationMarker(clip, name, time)
    if name == "left_touch" or name == "right_touch" then
        -- touch the ball with that foot
    end
end
SignatureBehavior
playAnimationTimeline(clip, options?)Starts a timeline and returns true. Options: speed (default 1; 0 holds), loop (default true), startTime (default 0), animate (default true: also play the clip on the model and keep the pose in step), blendTime (default 0.2), layer, mask and priority (draw the clip on an animation layer; see below), and duration, the clip's length in seconds. duration overrides the recorded length, so use it only for a clip that has none, as a literal number. Returns false, with a warning, and starts nothing for bad options (such as a negative speed, an unknown mask, or mask or priority without layer) or a clip with no recorded length and no duration.
stopAnimationTimeline()Stops the timeline.
setAnimationTimelineSpeed(speed)Changes the running timeline's speed. Returns false when there is none.
seekAnimationTimeline(time)Moves the timeline to time seconds. It does not report the markers it skips. Returns false when there is no timeline.
getAnimationTimeline(){clip, time, speed, loop, duration, loops, playing}, or nil with no timeline. loops counts how many times the clip has wrapped; playing is false once a non-looping timeline has ended.
getClipDuration(clip)The clip's recorded length in seconds, or nil.
getAnimationMarkers(clip?)The object's markers as {clip, name, time} tables, for one clip in time order, or with no argument for every clip, sorted by clip name and then by time.
  • onAnimationMarker(clip, name, time) runs before update for every marker the step crossed, in order, and again on every loop. A step that covers several whole cycles reports at most four of them. onAnimationTimelineFinished(clip) runs when a non-looping timeline ends.
  • A timeline advances by the same deltaTime as update, so it follows the game's time scale and stops while the game is paused. Each scripted object has one timeline; starting another replaces it, and markers of the old one still due in that step are dropped.
  • The editor records each clip's length when it loads the model and its attached animation files. If you attached a file outside the editor, such as through MCP, open the scene once. Publishing warns about any marked clip with no recorded length, and about markers past a clip's end.
  • In single player, automatic locomotion can fight a timeline that draws its clip. Pass animate = false, or stop calling updateAutoAnimation while the timeline runs.

onAnimationFinished is different: it comes from the drawn clip, so it only fires where something is drawn and never on a room's server. Use timelines for gameplay. In a multiplayer room see Build and test a multiplayer game for showing the clip on other players' screens.

Draw a timeline on a layer

A timeline that draws its clip plays it as the base animation, which replaces locomotion. Pass layer to draw it on that animation layer instead, as playAnimationLayer would, so locomotion keeps running underneath. mask and priority are the layer's, as described under Animation layers below, and need layer.

function throw()
    -- The legs keep running; the markers still drive the gameplay.
    gameObject.playAnimationTimeline("throw", { loop = false, layer = "action", mask = "upperBody" })
end

function onAnimationMarker(clip, name, time)
    if name == "release" then
        -- let go of the ball
    end
end
  • The layer is kept in step with the timeline's clock, speed changes and seeks included. It holds its last frame until the timeline finishes and then fades out over blendTime; stopping the timeline fades it out the same way. The layer still reports onAnimationLayerFinished like any layer.
  • layer changes only how the clip is drawn. Markers, onAnimationTimelineFinished and their timing are exactly the same with or without it. A multiplayer room's server and a predicted copy, which never draw, accept the option and draw nothing.
  • The options are checked the same way on every runtime, so a call refused in Preview is refused on the room server too.

Cancel an interrupted action safely

A marker is the release trigger; a timer is only a way to abandon a stuck action. Validate the marker before starting, accept it only for the active action and clear the pending flag before applying the effect. Stop the timeline and clear pending work when the action is interrupted, the character loses its held object, or the round changes. If a non-looping timeline ends without its expected marker, cancel rather than applying the effect late.

-- Add this pattern to the character's own script.
-- Call beginThrow() only after your rules approve the action.
local pendingRelease = false
local releaseSeq = 0

function beginThrow()
    if pendingRelease then return false end
    local found = false
    for _, marker in ipairs(gameObject.getAnimationMarkers("throw")) do
        if marker.name == "release" then found = true end
    end
    if not found then return false end
    pendingRelease = gameObject.playAnimationTimeline("throw", {
        loop = false, speed = 2.2,
        layer = "action", mask = "upperBody"
    })
    return pendingRelease
end

function cancelThrow()
    pendingRelease = false
    gameObject.stopAnimationTimeline()
end

function onAnimationMarker(clip, name, time)
    if clip ~= "throw" or name ~= "release" or not pendingRelease then return end
    pendingRelease = false
    releaseSeq = releaseSeq + 1
    gameObject.setVar("release_seq", releaseSeq)
end

function onAnimationTimelineFinished(clip)
    if clip == "throw" then pendingRelease = false end
end

Declare a numeric object variable named release_seq, initially 0, for this example. It reports a release request, not a completed throw: the single-player rules or room authority consume each new counter once, recheck ownership, alive state and round, and apply the release there. Capture the current counter when accepting a new action so an earlier marker cannot release a later throw. The callback reports to this object's script, not to the scene script. Integrate these handlers with any existing ones, and call cancelThrow() from your interruption and round-reset paths; add a timeout that cancels if the expected timeline stops or is replaced.

At speed 2.2 a marker at 0.8 clip seconds is crossed after roughly 0.364 simulation seconds from a zero start. The callback runs on the crossing step; pause and time scale affect it. In multiplayer, object variables stay local to each runtime: publish the authority's current action sequence, timeline time and speed in avatar state for presentation scripts. See “Synchronize a throw with its animation” in Build and test a multiplayer game for late joins, drift correction, canonical ownership and cleanup.

Automatic locomotion

enableAutoAnimation(config) picks a clip each frame from the character's velocity, ground contact, and crouch state, so a controller does not have to name clips at the right moment. Call updateAutoAnimation() every frame — nothing happens without it. disableAutoAnimation() stops it, and getAnimationState() returns the current state name.

function init()
    gameObject.enableAutoAnimation({
        idle = "idle",
        walk = "walk",
        run = "run",
        walkBackward = "walk_backward",
        strafeLeft = "strafe_left",
        strafeRight = "strafe_right",
        forwardLeft = "forward_left",
        forwardRight = "forward_right",
        backwardLeft = "backward_left",
        backwardRight = "backward_right",
        turnLeft = "turn_left",
        turnRight = "turn_right",
        jump = "jump",
        fall = "fall",
        land = "land",
        crouchIdle = "crouch_idle",
        crouchWalk = "crouch_walk"
    })
end

function update(deltaTime)
    -- move the character first, so the state machine reads this frame's motion
    gameObject.updateAutoAnimation()
end

Every key is optional, and every one defaults to the clip name shown above — so a model whose clips already use these names needs no config at all. enableAutoAnimation({}) is a complete call.

Animation in a multiplayer room

Scripts written this way keep working in a room. Every player's browser animates every character automatically from its movement — the same idle, walk, run, directional, turn, jump, fall, land and crouch states — so a character's control script does not animate anything itself there: enableAutoAnimation, disableAutoAnimation and setAnimationSpeed set the character's configuration for its own player's screen, and updateAutoAnimation, playAnimation, stopAnimation and the getters do nothing (getAnimationNames() returns an empty list and getAnimationState() returns nil).

Other players see a character animated with the default clip names in the table below, whatever configuration its script passes. For a model whose clips are named differently, give the character a Room animation (multiplayer.animation) in the inspector's Multiplayer section: it takes the same keys as enableAutoAnimation, plus a playback speed per state, and every screen — the controlling player's included — plays those clips in place of the script's configuration. Play an explicit clip — an emote, a hit reaction — from a GUI or camera script; that takes the character over on that browser until the script calls releaseAnimation() on it, after which the engine animates it again from the next frame. An animation layer played from there does not: locomotion keeps running under it (see Animation layers), so in a room prefer a layer for emotes and other one-off moments. setAnimationSpeed called from a camera, GUI or presentation script changes that clip's rate on that browser without taking the character over, which is how to match a clip's speed on every screen. See "Character animation in a room" in Build and test a multiplayer game.

KeyDefaultWhen it plays
idle"idle"On the ground, below the walk threshold
walk"walk"On the ground, above the walk threshold
run"run"On the ground, above the run threshold
jump"jump"Once, on leaving the ground
fall"fall"Looped, once the takeoff finishes
land"land"Once, on touching down
crouchIdle"crouch_idle"Crouched and still
crouchWalk"crouch_walk"Crouched and moving
walkBackward"walk_backward"Moving backwards, relative to the way it faces
strafeLeft"strafe_left"Sidestepping to the character's left
strafeRight"strafe_right"Sidestepping to the character's right
forwardLeft"forward_left"Travelling forward-left
forwardRight"forward_right"Travelling forward-right
backwardLeft"backward_left"Travelling backward-left
backwardRight"backward_right"Travelling backward-right
turnLeft"turn_left"Standing still and turning left
turnRight"turn_right"Standing still and turning right
walkThreshold0.1Speed in m/s at which idle becomes walk
runThreshold4.0Speed in m/s at which walk becomes run
turnThreshold0.5Yaw rate in rad/s above which a stationary character is turning
blendTime0.2Crossfade into a looping state
oneShotBlendTime0.12Crossfade into the short jump takeoff
landBlendTime0.25Crossfade into the longer land recovery

The air is two states, not one

jump plays once on takeoff and hands over to a looping fall when it finishes; land plays once on touchdown and then gives way to a ground state. That is why a takeoff clip should be the push-off alone. A clip that includes its own crouch and wind-up will appear to start late, because the character has already left the ground by the time it plays — the physics jump is instant and the animation is not.

A landing is cut short the moment the player moves off, so a long recovery clip does not lock the character in place.

oneShotBlendTime is short enough not to swallow the 0.30s takeoff, while landBlendTime eases into the much longer 1.40s touchdown. Finished one-shots are fully stopped and uncached before the next state, so a clamped final pose cannot keep blending into later movement.

A turn clip animates the feet, not the heading

Your script owns which way the character faces — the state machine reaches for turn_left or turn_right precisely because it saw that heading change. So the bundled turn clips shuffle the feet and shift the weight without rotating the model: the rotation you see is the one your controller applied.

That matters if you supply your own. Mixamo's turn animations are real 90-degree pivots, and bundling one unchanged rotates the character twice — the model swings ahead of its facing and snaps back each time the clip loops. The bundled ones have that pivot taken out at build time. If a turn looks like it over-rotates, this is why.

Missing clips fall back rather than failing

A state whose clip the model does not carry drops to the nearest one it does: run and the sideways and diagonal states onto walk, the backward diagonals onto walk_backward and then walk, a turn onto the matching strafe, crouch onto the standing clips, fall onto jump, and land onto idle, which is where every chain ends. The directional and turning states go further: they are not chosen at all unless the model has that clip, so a model without walk_backward backs up with its ordinary walk and run clips. A model with only idle, walk, run and jump therefore animates everywhere — and with no fall clip to hand over to, its jump loops for the whole descent instead of playing once.

A clip that is missing with no usable fallback is reported once in the browser console, not once per frame.

Animation layers

A layer plays a clip on part of the skeleton on top of the object's base animation, which keeps running underneath: arms cradling a ball while the legs run and strafe, a throw that leaves the stride alone, a full-body flinch that hands back to locomotion as it fades. The base animation is whatever playAnimation or automatic locomotion is playing. Layers work on characters, and on meshes and ragdolls with a skeleton.

Each layer has a name you choose and plays one clip at a time. Layers stack by priority, and each covers the bones its mask names.

-- "hold_ball" and "throw_ball" stand for clips added with Add Animation.
local carrying = true

function init()
    gameObject.enableAutoAnimation({})
end

function update(deltaTime)
    -- move the character first, then let locomotion pick the base clip
    gameObject.updateAutoAnimation()

    if carrying then
        -- The same clip and mask as last frame changes nothing,
        -- so this is safe to call every frame.
        gameObject.playAnimationLayer("hold", "hold_ball", { mask = "arms" })
    else
        gameObject.stopAnimationLayer("hold", 0.2)
    end

    if carrying and input.primaryFire then
        carrying = false
        -- A one-shot on a higher-priority layer: it wins on the bones it
        -- shares with "hold", and the legs keep running underneath.
        gameObject.playAnimationLayer("throw", "throw_ball", {
            mask = "upperBody",
            loop = false,
            priority = 10,
            blendTime = 0.1,
        })
    end
end

function onAnimationLayerFinished(layer, clip)
    if layer == "throw" then
        carrying = true -- ready for the next ball
    end
end
SignatureBehavior
playAnimationLayer(layer, clip, options?)Plays clip on the named layer, creating the layer if it is new. Returns true when the layer is playing that clip. Calling it again with the same clip and mask on the same layer does nothing, so it can be called every frame; a different clip crossfades from the one there over blendTime, and takes the new call's options with it. A clip from a separate animation file loads first: the call returns false and the layer starts when the file arrives, unless a later call for that layer asked for something else. Returns false, with one console warning, for a missing layer or clip name, a clip the object does not have, an invalid option, or a clip that animates none of the mask's bones.
stopAnimationLayer(layer?, fadeOutTime?)Stops one layer, or every layer with no name, fading out over fadeOutTime seconds. The default is 0, at once.
setAnimationLayerWeight(layer, weight, fadeTime?)Changes a playing layer's weight, from 0 to 1, over fadeTime seconds (default 0). Returns false when there is no such layer.
setAnimationLayerSpeed(layer, speed)Changes a playing layer's rate, 0 or more. Returns false when there is no such layer.
seekAnimationLayer(layer, time)Moves the layer's playhead to time seconds, clamped to the clip's length, for example to correct it against a replicated time. A finished one-shot sought back before its end plays on from there. Returns false when there is no such layer.
getAnimationLayer(layer){layer, clip, mask, time, duration, weight, speed, loop, priority, playing, finished}, or nil when there is no such layer: a one-shot that has faded out is gone. weight is the layer's share on screen now, fades included; playing is false once it has finished or is being stopped.
getAnimationLayers()Every layer, as the same tables, lowest priority first.
getAnimationMaskBones(mask){bones = {...}, missing = {...}}: the model's bones the mask covers, and the names it gave that the model lacks.

Options

Every option of playAnimationLayer is optional.

OptionDefaultMeaning
mask"fullBody"Which bones the layer plays: a preset name or a table (see Masks below).
looptrueWhether the clip repeats. A layer with loop = false is a one-shot.
blendTime0.15Seconds to fade the layer in, and to crossfade when the layer changes clip.
speed1Playback rate, 0 or more.
weight1The layer's share of its bones, from 0 to 1. At 1 the layer replaces what is underneath on those bones; 0.5 is half layer and half what is underneath.
startTime0Seconds into the clip to start from.
priority0A higher-priority layer wins over a lower one on the bones they share. Layers of equal priority stack in the order they were created.
translationsfalseOnly bone rotations play by default, so a clip made for a differently sized character cannot stretch the body. true also plays bone positions.
onFinish"fadeOut"For a one-shot: "fadeOut" fades the layer out over fadeOutTime once its last frame is reached and then removes it; "hold" keeps the last frame until you stop the layer.
fadeOutTimethe blendTimeSeconds a finished one-shot takes to fade out.

Masks

  • "fullBody": every bone. Use it with a high priority for a full-body interrupt, such as a dodge or a hit reaction, that hands back to locomotion as it fades.
  • "upperBody": the spine and everything above it, which is the chest, neck, head and both arms. It starts from the first of Spine, Spine1 or Chest the model has.
  • "arms": both arms from the shoulder down to the fingers. Each side starts from the first of LeftShoulder, LeftArm or LeftUpperArm (and the same on the right) the model has.
  • A table, { bones = {"LeftShoulder", "RightShoulder"}, exclude = {"LeftHand"}, subtree = true, weights = { Spine = 0.4 } }. bones and exclude each take a bone name or a list of them, and take each named bone with its children unless subtree = false. Leaving out bones means the whole skeleton, so exclude alone can carve it. weights gives a named bone alone, not its children, its own weight from 0 to 1, and adds it if the rest of the mask left it out; a weight of 0 removes it.

Bone names in a mask match loosely, as they do for bone sockets below: "Spine" finds mixamorig:Spine. A name the model has no bone for is left out of the layer and reported once in the browser console. Call getAnimationMaskBones(mask) to see exactly which bones a mask covers on this model.

Finishing, and what layers leave alone

  • When a one-shot layer reaches its end, the object's own script gets onAnimationLayerFinished(layer, clip). Layer clips never call onAnimationFinished, which keeps meaning the base animation. Like it, the callback comes from the drawn clip, so it fires only where something is drawn.
  • Calling playAnimationLayer every frame with a one-shot does not restart it while it plays, holds or fades out; once it has faded out and gone, the next call starts it again. Start a one-shot when the event happens, not every frame.
  • Layers are invisible to isAnimationPlaying and getAnimationTime, which report the base animation only. Use getAnimationLayer for a layer.
  • playAnimation, stopAnimation and enableAutoAnimation change only the base animation and never stop a layer. setAnimationSpeed(speed) with no clip name scales every layer too; setAnimationLayerSpeed sets one layer's rate on top of it. Stopping the run clears every layer.

Changed on 19 October 2026

Before layers existed, playAnimation with a blendTime of 0 and stopAnimation() with no name stopped every action on the object. They now stop only the object's own clips and leave its layers playing. Stop layers with stopAnimationLayer.

Layers are presentation-only in a multiplayer room

In a room, layer calls work only in camera, GUI and presentation scripts, which run on each player's browser. In an authority or prediction script they do nothing: playAnimationLayer and the setters return false, and getAnimationLayers returns an empty list. Nothing about a layer is sent to other players, so drive layers on every browser, the owner's included, from replicated state: the authority publishes what the character is doing, for example with avatar state, and each browser plays the holding layer while it says carrying and a one-shot when its action counter rises. Unlike playAnimation from a presentation script, a layer never stops the engine's automatic character animation, so locomotion keeps running under it. A camera or GUI script driving another object's layer gets no onAnimationLayerFinished, which goes to that object's own script; poll getAnimationLayer(layer) instead. See Build and test a multiplayer game.

Check that a clip fits the model

A clip drives a model by bone name. A clip made for a different skeleton, or one that animates bones the model leaves out (often fingers or toes), cannot move those bones. When a clip from a separate file loads, the tracks for bones the model lacks are dropped, and the browser console gets one line for that clip instead of dozens of PropertyBinding warnings.

getAnimationDiagnostics() returns one table per loaded clip:

for _, report in ipairs(gameObject.getAnimationDiagnostics()) do
    if report.status ~= "ok" then
        print(report.clip .. ": " .. (report.advice or report.status))
    end
end
FieldMeaning
clipThe clip's name, as playAnimation knows it.
trackCount, boundTrackCountHow many tracks the clip has, and how many of them name a bone this model has.
missingBonesEach bone the clip animates that the model lacks, listed once.
status"ok" when every track binds, "partial" when some do, "incompatible" when none do: the clip was made for a different skeleton.
positionScalePresent only when the clip's bone positions are far from the model's rest pose, as a ratio: about 100 usually means a clip in centimetres on a model in metres (or the reverse), which collapses or twists the pose. It is reported only beyond 20 either way, so a clip that starts or stays lying on the floor is not mistaken for a unit problem.
adviceOne sentence saying what to do. Absent when status is "ok".

Clips that have not loaded yet are not listed, so preload them first. Retargeting a clip onto a different skeleton is not supported: for an incompatible clip, export the motion from the same rig as the model. Mixamo motions are the exception, because every Mixamo character shares one skeleton (see "External animations" above). For a unit mismatch, re-export one of the two files so their units match.

In the editor, the animation preview in the inspector shows a Rig compatibility box for any clip that is not "ok", with how many of its tracks bind, which bones are missing, and the same advice.

Attach objects to bones

A character, or a mesh with a skeleton, can read its bones and hold other objects at them: a sword in a hand, a hat on a head.

SignatureBehavior
getBoneNames()Lists the model's bones.
getBoneWorldPosition(name)The bone's world position as animated this frame, {x, y, z}, or nil when there is no such bone.
getBoneWorldRotation(name)The bone's world rotation as a quaternion, {x, y, z, w}, or nil.
attachToBone(object, boneName, offset?)Called on the character or mesh. Holds object (a handle or an id) at the bone every frame until it is released. Returns true when attached.
detachFromBone(object?)Releases one held object, or with no argument everything this object holds. Returns true if anything was released.
getBoneAttachments()Lists what this object holds, as { objectId = ..., bone = ... } tables.

Bone names match exactly first, then loosely, ignoring case, separators and Mixamo's mixamorig prefix, so "RightHand" finds mixamorig:RightHand. Any named node of the model, such as a Grip empty exported with it, works as a bone.

function init()
    local sword = gameObject.getVar("sword") -- an object_ref variable
    local attached = gameObject.attachToBone(sword, "RightHand", {
        position = { x = 0, y = 0.05, z = 0.25 }, -- metres along the bone's axes
        euler = { x = 90, y = 0, z = 0 },          -- degrees
    })
    if not attached then
        for _, name in ipairs(gameObject.getBoneNames()) do
            print(name)
        end
    end
end

The offset is optional. Its position is in metres along the bone's axes and ignores the rig's own scale (Mixamo bones carry a 0.01 scale). Give the rotation either as rotation = {x, y, z, w}, a quaternion, or as euler = {x, y, z} in degrees, applied X, then Y, then Z. Bone axes differ between rigs, so expect to tune the offset until the object sits right. A malformed offset is refused and reported as a script error.

The held object is placed after animation and character movement each frame, so it sits on the hand of the pose that is drawn, and it is in the hand from the moment of the call. What happens to its physics depends on its body:

  • A dynamic body becomes kinematic while held and is swept to the hand, so it pushes what it hits and gravity no longer pulls it away. Detaching makes it dynamic again with the hand's velocity, which is how a weapon is thrown.
  • A kinematic body, including any trigger volume, stays kinematic and is swept the same way, so a sensor blade reports onTriggerEnter as it sweeps through characters and bodies.
  • A static body is moved to the hand without pushing anything.
  • An object with no body is only drawn there.

attachToBone returns false for a missing object or bone, for the object itself, and for an object the character is a child of. Stopping the run releases everything.

Bone sockets are presentation-only in a multiplayer room

The room server never animates a skeleton, so in an authority or prediction script the bone, diagnostics, preload and playhead calls on this page do nothing: attachToBone, detachFromBone, seekAnimation, preloadAnimations and the readiness checks return false, getBoneNames, getBoneAttachments and getAnimationDiagnostics return empty lists, and the rest return nil. Attach a weapon from a camera, GUI or presentation script, which runs on each player's browser. What a bone holds there is decoration on each screen, so never decide a hit from a bone-held hitbox: send an action and resolve the hit on the room server. See Build and test a multiplayer game.

Holding a replica is visual only. When a browser attaches an object it only displays, such as a replicated prop or ball, or another player's character or vehicle, its mesh is drawn on the bone every frame, winning over where multiplayer.hold draws a held prop, but its body is never made kinematic or moved, because the room server owns where it really is. detachFromBone hands the drawing back to replication: a ball the server still holds goes back to its hold offset, and a released one to its flight. This happens automatically; there is no setting for it.

Clips on the default character

A character with no mesh asset of its own renders the bundled default model, which ships with thirty clips. They are the names in the table above plus a set for scripts to drive directly:

PurposeClips
Locomotionidle, walk, run, walk_backward, strafe_left, strafe_right, forward_left, forward_right, backward_left, backward_right
Turning on the spotturn_left, turn_right
Airjump, fall, land
Crouchedcrouch_idle, crouch_walk
Combatattack, hit_reaction, death, aim_idle, fire_idle, reload
Stealth and traversalsneak_walk, roll, vault, climb
Emotewave, look_around

walk_forward is also present, as a second name for walk.

The first seventeen are reachable through enableAutoAnimation; the rest are played with playAnimation at the moment your script wants them. The character's Current Animation dropdown in the inspector lists whichever clips the loaded model actually has, which is the quickest way to see them without running anything.

The default character changed on 14–16 September 2026

It first replaced the old four-clip set — idle, run, walk, and tpose — with the full locomotion set, then added the four diagonal clips. Scripts that referenced tpose will no longer find it. Existing clip names were otherwise retained.