animation
Observe what the engine is animating: every body it is posing, the clips driving each one and where their playheads are, how many of a body's bones a clip's retarget reached, and — for a body that is not moving — the one reason why, from a closed set. Ragdoll a skinned character or creature (animation.ragdoll): its skeleton carried by physics bodies for a death, a knockout, a hit reaction or a limp limb, every bone body a body the Physics calls take.
require("@builtin::modules.api.engine.animation") -- animation (also available as global 'animation')
The animation namespace: 53 functions.
globals/animation/animating
animation.animating() -> { AnimationBody }
The bodies the engine measured a changing pose on — what is animating right now.
Returns { AnimationBody } — An array of AnimationBody.
for _, b in animation.animating() do for _, c in b.clips do print(b.entity, c.name, c.weight) end end
globals/animation/bodies
animation.bodies() -> { AnimationBody }
Every body the engine holds animation state for.
Returns { AnimationBody } — An array of AnimationBody.
for _, b in animation.bodies() do print(b.entity, b.matched .. "/" .. b.total) end
globals/animation/body
animation.body(entityId: string | EntityRef) -> AnimationBody?
The report for one body, or nil when the engine holds no animation state for it. Accepts the body itself or any ancestor of it, so a character root answers for the skinned body underneath it.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
Returns AnimationBody? — An AnimationBody, or nil.
local b = animation.body(hero.id); print(b and b.reason)
globals/animation/clips
animation.clips(entityId: string | EntityRef) -> { AnimationClip }
The clips contributing to a body's pose right now, with their playheads and their retarget coverage.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
Returns { AnimationClip } — An array of AnimationClip.
for _, c in animation.clips(hero.id) do print(c.name, c.time, c.matched) end
globals/animation/coverage
animation.coverage(entityId: string | EntityRef) -> (number, number)
How many of a body's bones the clips driving it actually reach.
Returns (matched, total). A clip that retargets onto nothing reads
(0, 50) while its playhead advances; a partial retarget reads its own
count, so 3 of 50 is as visible as none.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
Returns (number, number) — (matched, total).
local m, t = animation.coverage(hero.id); print(m .. "/" .. t)
globals/animation/declare
animation.declare(entityId: string, facts: { [string]: any })
Publish what an animator is running on a body, so the observation names
its clips, playheads and retarget coverage beside the pose the engine
measures. The shipped animators declare through AnimGraph:publish; a
custom animator calls this itself whenever what it runs changes. A clip
that names its sampler (the handle skeleton.bindClip returned) reports
the playhead that sampler last sampled at, and each sample keeps the
declaration current; an animator declaring a clip without its sampler
declares on every frame it runs, since nothing else shows it is still
running. A declaration stands until the animator declares again or calls
animation.forget.
Parameters
entityIdstring— The body the animator drives.facts{ [string]: any }—{ driver, bound, playing, outputKind, failure, clips }, where each clip is{ name, nodeKind, sampler, time, duration, playing, finished, looping, weight, matched, total, unmatched };unmatchedlists the bones the clip leaves at rest that fill a role of the body's retarget profile first.
animation.declare(body.id, { driver = "MyAnimator", playing = true, clips = {} })
globals/animation/forget
animation.forget(entityId: string)
Drop the declaration and the pose evidence the engine holds for one body. An animator calls this when it releases a body, so the observation reports the body as undriven from the next frame.
Parameters
entityIdstring— The body to drop.
animation.forget(body.id)
globals/animation/observe
animation.observe() -> AnimationObservation
Report what the engine is posing right now and why a body is not moving. One read covering every body the engine holds animation state for, each with the pose evidence the engine measured on its armature beside the clips the animator driving it declared. Answers in edit mode as well as play mode.
Returns AnimationObservation — An AnimationObservation.
local a = animation.observe(); print(a.animatingCount, a.riggedBodyCount)
for _, b in animation.observe().bodies do print(b.entity, b.animating, b.reason) end
globals/animation/poseDue
animation.poseDue(entityId: string | EntityRef) -> boolean
Whether the engine evaluates this body's pose this frame. The engine
decides each rigged body's interval once a frame from what the views see
of it, and every shipped animator (AnimGraph:tick, the graphs the engine
runs, AvatarAnimator) evaluates only on the frames this answers true,
carrying the time of the frames between into the next evaluation. A custom
animator does the same: skip the evaluation and keep the delta when this
is false. A body the engine does not schedule answers true.
Parameters
entityIdstring | EntityRef— The skinned body's id, or an EntityRef.
Returns boolean — true on a frame the body is evaluated on.
if animation.poseDue(body.id) then print("evaluated this frame") end
globals/animation/poseRate
animation.poseRate(entityId: string | EntityRef) -> AnimationPoseRate?
How often the engine evaluates a body's pose and why, as an
AnimationPoseRate. Accepts the body or an entity above it, answering for
the first scheduled body beneath. nil when no body there is scheduled.
Parameters
entityIdstring | EntityRef— The body's id, an entity above it, or an EntityRef.
Returns AnimationPoseRate? — An AnimationPoseRate, or nil.
local r = animation.poseRate(hero.id); print(r and r.interval, r and r.reason)
globals/animation/poseRates
animation.poseRates() -> AnimationPoseRates
Every scheduled body's rate in total, with the settings the intervals
are chosen by, as an AnimationPoseRates: how many bodies are evaluated
every frame, how many for each reason, and the share of full-rate
evaluations a frame makes.
Returns AnimationPoseRates — An AnimationPoseRates.
local t = animation.poseRates(); print(t.bodies, t.evaluationShare, t.byReason.offscreen)
globals/animation/ragdoll
animation.ragdoll(entityId: string | EntityRef, opts: (boolean | RagdollOptions)?) -> string
Ragdoll a skinned body: its skeleton is carried by physics bodies that
fall, tumble and pose the mesh, for a death, a knockout, a hit reaction, a
stunt fall or a limp limb. Works on any rigged skeleton: a humanoid (the
built-in avatar and any imported humanoid rig) gets bodies sized for each
body part and anatomical joints (hinged knees and elbows, cones at the
shoulders, hips and neck); any other rig (a quadruped, a bird, a tail, a
robot arm) gets a capsule along every bone and ball joints. The first call
builds the ragdoll on the next frame, false included (its bodies follow
the animation until it is switched on, so its bones can be read and
jointed first); animation.ragdollState reads it back. false hands the
body back to its animation: every bone moves from where the ragdoll left
it to the pose its animation holds over blend seconds (play a get-up
clip on the body as you call it, and the body rises into it; a body
nothing animates goes back to the pose it held when it fell), and the
entity this call names (or the nearest one above it that also holds the
skeleton's bones) is moved to stand the body up where it lies (over the
place the hips lie, turned the way the body lies). true ragdolls it
again. A ragdoll poses the body whatever animates it: a clip player, an
animation graph or a locomotion program.
The options table takes active (default true), limp (bone names: only
those bones and the bones below them go limp while the rest keep
animating), blend (the seconds a bone handed back to its animation takes
to reach it, default 0.5; 0 hands it back in one frame), standUp
(default true; false leaves the entity this call names where it is when
the body is handed back), mass (the whole body's mass in kilograms; by default bodies
weigh 1000 kg per cubic metre of collider, about 120 kg for the built-in
avatar, so pass a person's 60 to 90 kg for a lifelike one) and bones (bone
name -> { shape = "capsule" | "box" | "sphere" | "none", radius, length, size = {x, y, z}, mass, joint = "ball" | "hinge" | "fixed", swing, twist, hinge = {min, max}, strength, damping }, sizes in metres and angles in
degrees). A description different from the last one rebuilds the ragdoll.
On a humanoid a bone is also named by its humanoid role (hips, spine,
chest, neck, head, leftshoulder, leftarm, leftforearm,
lefthand, leftupleg, leftleg, leftfoot and the right ones), so
one description fits every humanoid rig.
Each bone body is the body of that bone's armature entity (its id in
ragdollState), so every Physics call takes it: Physics.addJoint to
hold a hand to a ledge (breakable with breakForce), Physics.applyImpulseAtPoint
for a hit, Physics.getVelocity, Physics.bodyState and Physics.contacts
to measure a fall.
Parameters
entityIdstring | EntityRef— The skinned entity, or any entity above it (a character root).opts(boolean | RagdollOptions)(optional) —true/false, or aRagdollOptionstable.
Returns string — The id of the skinned entity the ragdoll is built on.
animation.ragdoll(enemy.id) -- collapse it
animation.ragdoll(enemy.id, false) -- back to its animation, standing up where it lies
animation.ragdoll(enemy.id, { active = false, blend = 1.2 }) -- a slower rise
animation.ragdoll(hero.id, { limp = { "leftarm" } }) -- one limp arm
animation.ragdoll(dummy.id, { mass = 75, bones = { head = { mass = 5, swing = 30 }, leftleg = { hinge = { -140, 0 } } } })
local hand = animation.ragdollBone(hero.id, "righthand"); Physics.addJoint(hand, ledge, { kind = "ball", breakForce = 3000 })
globals/animation/ragdollBone
animation.ragdollBone(entityId: string | EntityRef, bone: string) -> string?
The entity a ragdoll's bone body answers to, by bone name or, on a
humanoid, by humanoid role (head, righthand, ...): the id to
pass Physics.addJoint, Physics.applyImpulseAtPoint,
Physics.getVelocity, Physics.bodyState, Physics.contacts and every
other Physics call. nil until the ragdoll is built, or when that bone
has no body of its own.
Parameters
entityIdstring | EntityRef— The skinned entity, or any entity above it.bonestring— The bone's name in the skeleton.
Returns string? — The bone body's entity id, or nil.
local head = animation.ragdollBone(dummy.id, "head"); print(Physics.getVelocity(head))
globals/animation/ragdollState
animation.ragdollState(entityId: string | EntityRef) -> RagdollState?
The ragdoll built on a skinned body: whether the simulation drives
it, its total mass, and every bone body with the entity it answers to (the
bone's armature entity), its shape and size in metres, its mass read off
the solver, whether it is simulated, and its joint. built reads false
until the engine has built it (the frame after animation.ragdoll), and
problems names anything the description asked for that the skeleton
could not give. Under multiplayer replication reads which peer simulates
the ragdoll (the owner of the synced entity at or above the body; every
other peer shows it from that peer's bone poses) and what it costs on the
wire.
Parameters
entityIdstring | EntityRef— The skinned entity, or any entity above it.
Returns RagdollState? — A RagdollState, or nil when the body carries no ragdoll.
local r = animation.ragdollState(hero.id); for _, b in r.bones do print(b.bone, b.mass, b.joint and b.joint.kind) end
globals/animation/setPoseRate
animation.setPoseRate(entityId: string | EntityRef, mode: string | number)
Pin how often a body's pose is evaluated, wherever it stands: "exact"
(every frame, for a character whose bones drive gameplay, attachments or
physics off screen as well as on), a number of frames (1 to 120), or
"auto" to return it to the interval the views decide. Applies to every
skinned body at or below the entity, from the next frame. Raises when no
entity at or below it carries a Skeleton, as a character whose model
has not loaded yet: pin it once its body is there.
Parameters
entityIdstring | EntityRef— The body, an entity above it, or an EntityRef.modestring | number—"exact","auto", or frames between two evaluations.
animation.setPoseRate(boss.id, "exact")
globals/animation/setPoseRateSettings
animation.setPoseRateSettings(settings: { [string]: any })
Change how the engine chooses each body's interval, replacing the
fields named (see PoseRateSettings): steps from the largest share of a
view's height down (a visible body takes the first step it spans, and the
last step's interval below them all), offscreenInterval for a body no
view holds, nearDistance in metres within which a body is evaluated
every frame, viewMarginDeg by which each view is widened, and enabled.
Raises naming the field when one cannot apply, and changes nothing then.
Parameters
settings{ [string]: any }— The fields to replace.
animation.setPoseRateSettings({ offscreenInterval = 30 })
globals/animation/whyStill
animation.whyStill(entityId: string | EntityRef) -> (string?, string?)
Why the body on an entity is not animating. Returns nil when it IS
animating, and otherwise one of deactivated, noRiggedSkeleton,
noGraph, clipUnreadable, noOutputNode, retargetPending, retargetMatchedNoRoles,
stopped, finished, paused, poseNotApplied, poseUnchanged — the
nearest cause, so the answer names the thing to change. A second return
carries the animator's own words when it could not build a graph.
An entity the engine holds no animation state for is answered from the
entity itself, in the same order the engine resolves a body it does hold:
one carrying no rigged Skeleton is noRiggedSkeleton, and a rigged one
nothing drives is noGraph. An id no entity carries is neither — the
reason is nil and the detail says so.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
Returns (string?, string?) — (reason, detail).
local why, detail = animation.whyStill(hero.id); if why then print(why, detail) end
modules/animation/animating
animating(): { AnimationBody }
The bodies the engine measured a changing pose on — what is animating right now.
for _, b in animation.animating() do for _, c in b.clips do print(b.entity, c.name, c.weight) end end
modules/animation/bodies
bodies(): { AnimationBody }
Every body the engine holds animation state for.
for _, b in animation.bodies() do print(b.entity, b.matched .. "/" .. b.total) end
modules/animation/body
body(entityId: string | EntityRef): AnimationBody?
The report for one body, or nil when the engine holds no animation state for it. Accepts the body itself or any ancestor of it, so a character root answers for the skinned body underneath it.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
local b = animation.body(hero.id); print(b and b.reason)
modules/animation/clips
clips(entityId: string | EntityRef): { AnimationClip }
The clips contributing to a body's pose right now, with their playheads and their retarget coverage.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
for _, c in animation.clips(hero.id) do print(c.name, c.time, c.matched) end
modules/animation/coverage
coverage(entityId: string | EntityRef): (number, number)
How many of a body's bones the clips driving it actually reach.
Returns (matched, total). A clip that retargets onto nothing reads
(0, 50) while its playhead advances; a partial retarget reads its own
count, so 3 of 50 is as visible as none.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
local m, t = animation.coverage(hero.id); print(m .. "/" .. t)
modules/animation/declare
declare(entityId: string, facts: { [string]: any })
Publish what an animator is running on a body, so the observation names
its clips, playheads and retarget coverage beside the pose the engine
measures. The shipped animators declare through AnimGraph:publish; a
custom animator calls this itself whenever what it runs changes. A clip
that names its sampler (the handle skeleton.bindClip returned) reports
the playhead that sampler last sampled at, and each sample keeps the
declaration current; an animator declaring a clip without its sampler
declares on every frame it runs, since nothing else shows it is still
running. A declaration stands until the animator declares again or calls
animation.forget.
Parameters
entityIdstring— The body the animator drives.facts{ [string]: any }—{ driver, bound, playing, outputKind, failure, clips }, where each clip is{ name, nodeKind, sampler, time, duration, playing, finished, looping, weight, matched, total, unmatched };unmatchedlists the bones the clip leaves at rest that fill a role of the body's retarget profile first.
animation.declare(body.id, { driver = "MyAnimator", playing = true, clips = {} })
modules/animation/forget
forget(entityId: string)
Drop the declaration and the pose evidence the engine holds for one body. An animator calls this when it releases a body, so the observation reports the body as undriven from the next frame.
Parameters
entityIdstring— The body to drop.
animation.forget(body.id)
modules/animation/observe
observe(): AnimationObservation
Report what the engine is posing right now and why a body is not moving. One read covering every body the engine holds animation state for, each with the pose evidence the engine measured on its armature beside the clips the animator driving it declared. Answers in edit mode as well as play mode.
local a = animation.observe(); print(a.animatingCount, a.riggedBodyCount)
for _, b in animation.observe().bodies do print(b.entity, b.animating, b.reason) end
modules/animation/poseDue
poseDue(entityId: string | EntityRef): boolean
Whether the engine evaluates this body's pose this frame. The engine
decides each rigged body's interval once a frame from what the views see
of it, and every shipped animator (AnimGraph:tick, the graphs the engine
runs, AvatarAnimator) evaluates only on the frames this answers true,
carrying the time of the frames between into the next evaluation. A custom
animator does the same: skip the evaluation and keep the delta when this
is false. A body the engine does not schedule answers true.
Parameters
entityIdstring | EntityRef— The skinned body's id, or an EntityRef.
if animation.poseDue(body.id) then print("evaluated this frame") end
modules/animation/poseRate
poseRate(entityId: string | EntityRef): AnimationPoseRate?
How often the engine evaluates a body's pose and why, as an
AnimationPoseRate. Accepts the body or an entity above it, answering for
the first scheduled body beneath. nil when no body there is scheduled.
Parameters
entityIdstring | EntityRef— The body's id, an entity above it, or an EntityRef.
local r = animation.poseRate(hero.id); print(r and r.interval, r and r.reason)
modules/animation/poseRates
poseRates(): AnimationPoseRates
Every scheduled body's rate in total, with the settings the intervals
are chosen by, as an AnimationPoseRates: how many bodies are evaluated
every frame, how many for each reason, and the share of full-rate
evaluations a frame makes.
local t = animation.poseRates(); print(t.bodies, t.evaluationShare, t.byReason.offscreen)
modules/animation/ragdoll
ragdoll(entityId: string | EntityRef, opts: (boolean | RagdollOptions)?): string
Ragdoll a skinned body: its skeleton is carried by physics bodies that
fall, tumble and pose the mesh, for a death, a knockout, a hit reaction, a
stunt fall or a limp limb. Works on any rigged skeleton: a humanoid (the
built-in avatar and any imported humanoid rig) gets bodies sized for each
body part and anatomical joints (hinged knees and elbows, cones at the
shoulders, hips and neck); any other rig (a quadruped, a bird, a tail, a
robot arm) gets a capsule along every bone and ball joints. The first call
builds the ragdoll on the next frame, false included (its bodies follow
the animation until it is switched on, so its bones can be read and
jointed first); animation.ragdollState reads it back. false hands the
body back to its animation: every bone moves from where the ragdoll left
it to the pose its animation holds over blend seconds (play a get-up
clip on the body as you call it, and the body rises into it; a body
nothing animates goes back to the pose it held when it fell), and the
entity this call names (or the nearest one above it that also holds the
skeleton's bones) is moved to stand the body up where it lies (over the
place the hips lie, turned the way the body lies). true ragdolls it
again. A ragdoll poses the body whatever animates it: a clip player, an
animation graph or a locomotion program.
The options table takes active (default true), limp (bone names: only
those bones and the bones below them go limp while the rest keep
animating), blend (the seconds a bone handed back to its animation takes
to reach it, default 0.5; 0 hands it back in one frame), standUp
(default true; false leaves the entity this call names where it is when
the body is handed back), mass (the whole body's mass in kilograms; by default bodies
weigh 1000 kg per cubic metre of collider, about 120 kg for the built-in
avatar, so pass a person's 60 to 90 kg for a lifelike one) and bones (bone
name -> { shape = "capsule" | "box" | "sphere" | "none", radius, length, size = {x, y, z}, mass, joint = "ball" | "hinge" | "fixed", swing, twist, hinge = {min, max}, strength, damping }, sizes in metres and angles in
degrees). A description different from the last one rebuilds the ragdoll.
On a humanoid a bone is also named by its humanoid role (hips, spine,
chest, neck, head, leftshoulder, leftarm, leftforearm,
lefthand, leftupleg, leftleg, leftfoot and the right ones), so
one description fits every humanoid rig.
Each bone body is the body of that bone's armature entity (its id in
ragdollState), so every Physics call takes it: Physics.addJoint to
hold a hand to a ledge (breakable with breakForce), Physics.applyImpulseAtPoint
for a hit, Physics.getVelocity, Physics.bodyState and Physics.contacts
to measure a fall.
Parameters
entityIdstring | EntityRef— The skinned entity, or any entity above it (a character root).opts(boolean | RagdollOptions)?(optional) —true/false, or aRagdollOptionstable.
animation.ragdoll(enemy.id) -- collapse it
animation.ragdoll(enemy.id, false) -- back to its animation, standing up where it lies
animation.ragdoll(enemy.id, { active = false, blend = 1.2 }) -- a slower rise
animation.ragdoll(hero.id, { limp = { "leftarm" } }) -- one limp arm
animation.ragdoll(dummy.id, { mass = 75, bones = { head = { mass = 5, swing = 30 }, leftleg = { hinge = { -140, 0 } } } })
local hand = animation.ragdollBone(hero.id, "righthand"); Physics.addJoint(hand, ledge, { kind = "ball", breakForce = 3000 })
modules/animation/ragdollBone
ragdollBone(entityId: string | EntityRef, bone: string): string?
The entity a ragdoll's bone body answers to, by bone name or, on a
humanoid, by humanoid role (head, righthand, ...): the id to
pass Physics.addJoint, Physics.applyImpulseAtPoint,
Physics.getVelocity, Physics.bodyState, Physics.contacts and every
other Physics call. nil until the ragdoll is built, or when that bone
has no body of its own.
Parameters
entityIdstring | EntityRef— The skinned entity, or any entity above it.bonestring— The bone's name in the skeleton.
local head = animation.ragdollBone(dummy.id, "head"); print(Physics.getVelocity(head))
modules/animation/ragdollState
ragdollState(entityId: string | EntityRef): RagdollState?
The ragdoll built on a skinned body: whether the simulation drives
it, its total mass, and every bone body with the entity it answers to (the
bone's armature entity), its shape and size in metres, its mass read off
the solver, whether it is simulated, and its joint. built reads false
until the engine has built it (the frame after animation.ragdoll), and
problems names anything the description asked for that the skeleton
could not give. Under multiplayer replication reads which peer simulates
the ragdoll (the owner of the synced entity at or above the body; every
other peer shows it from that peer's bone poses) and what it costs on the
wire.
Parameters
entityIdstring | EntityRef— The skinned entity, or any entity above it.
local r = animation.ragdollState(hero.id); for _, b in r.bones do print(b.bone, b.mass, b.joint and b.joint.kind) end
modules/animation/setPoseRate
setPoseRate(entityId: string | EntityRef, mode: string | number)
Pin how often a body's pose is evaluated, wherever it stands: "exact"
(every frame, for a character whose bones drive gameplay, attachments or
physics off screen as well as on), a number of frames (1 to 120), or
"auto" to return it to the interval the views decide. Applies to every
skinned body at or below the entity, from the next frame. Raises when no
entity at or below it carries a Skeleton, as a character whose model
has not loaded yet: pin it once its body is there.
Parameters
entityIdstring | EntityRef— The body, an entity above it, or an EntityRef.modestring | number—"exact","auto", or frames between two evaluations.
animation.setPoseRate(boss.id, "exact")
modules/animation/setPoseRateSettings
setPoseRateSettings(settings: { [string]: any })
Change how the engine chooses each body's interval, replacing the
fields named (see PoseRateSettings): steps from the largest share of a
view's height down (a visible body takes the first step it spans, and the
last step's interval below them all), offscreenInterval for a body no
view holds, nearDistance in metres within which a body is evaluated
every frame, viewMarginDeg by which each view is widened, and enabled.
Raises naming the field when one cannot apply, and changes nothing then.
Parameters
settings{ [string]: any }— The fields to replace.
animation.setPoseRateSettings({ offscreenInterval = 30 })
modules/animation/whyStill
whyStill(entityId: string | EntityRef): (string?, string?)
Why the body on an entity is not animating. Returns nil when it IS
animating, and otherwise one of deactivated, noRiggedSkeleton,
noGraph, clipUnreadable, noOutputNode, retargetPending, retargetMatchedNoRoles,
stopped, finished, paused, poseNotApplied, poseUnchanged — the
nearest cause, so the answer names the thing to change. A second return
carries the animator's own words when it could not build a graph.
An entity the engine holds no animation state for is answered from the
entity itself, in the same order the engine resolves a body it does hold:
one carrying no rigged Skeleton is noRiggedSkeleton, and a rigged one
nothing drives is noGraph. An id no entity carries is neither — the
reason is nil and the detail says so.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
local why, detail = animation.whyStill(hero.id); if why then print(why, detail) end
tools/animation/observe
animation.observe(target?: (string | EntityRef)) -> AnimObserveResult
What the engine is posing right now, one line per body: whether its pose is actually changing, the clip driving it with its playhead, how many of its bones that clip reaches, and — when it is not moving — the one reason why. The clip driving a body is the one carrying the most weight in its graph (weight), so a blend names the clip its pose comes from; animation.body(entity).clips lists every clip it blends. clipState says where the driving clip stands: pending while its retarget bakes, failed, partial (bones that fill a role of the body's mapping left at rest, those roles named in unreachedRoles) or full, and is nil when no clip drives the body or the bones left at rest cannot be told apart by role; a body held still by its skeleton's mapping, or reached in part, names the next step (avatar.inspect) in next. Call it with no arguments for every body in the scene, or pass an entity to narrow it to that one (a character root resolves down to the skinned body under it).
Parameters
target(string | EntityRef)(optional)
Returns AnimObserveResult
"hero"
tools/animation/play
animation.play(animation: string | AssetRef<animation>, entityArg: string | EntityRef, opts?: AnimPlayOpts) -> AnimPlayResult
Play an animation clip on an entity's skinned body for a test window, then clean up. Resolves animation by identity or name and entity by id or name, finds the SkinnedModel to drive, and plays it through the canonical AnimGraph — the same path ClipPlayer uses. Returns { ok = false, error } when the clip, the entity, or a SkinnedModel under it cannot be found. When the body already runs an animation the clip overrides it for the window and the original resumes untouched on cleanup.
Parameters
animationstring | AssetRef<animation>entityArgstring | EntityRefoptsAnimPlayOpts(optional)
Returns AnimPlayResult
"A_Walk_F_Masc", "hero"
"Idle", "hero", { offset = "5s", loop = true, duration = 8 }
typed/builtin//modules/api/engine/animation/animation/animating
animation.animating() -> { AnimationBody }
The bodies the engine measured a changing pose on — what is animating right now.
Returns { AnimationBody } — An array of AnimationBody.
for _, b in animation.animating() do for _, c in b.clips do print(b.entity, c.name, c.weight) end end
typed/builtin//modules/api/engine/animation/animation/bodies
animation.bodies() -> { AnimationBody }
Every body the engine holds animation state for.
Returns { AnimationBody } — An array of AnimationBody.
for _, b in animation.bodies() do print(b.entity, b.matched .. "/" .. b.total) end
typed/builtin//modules/api/engine/animation/animation/body
animation.body(entityId: string | EntityRef) -> AnimationBody?
The report for one body, or nil when the engine holds no animation state for it. Accepts the body itself or any ancestor of it, so a character root answers for the skinned body underneath it.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
Returns AnimationBody? — An AnimationBody, or nil.
local b = animation.body(hero.id); print(b and b.reason)
typed/builtin//modules/api/engine/animation/animation/clips
animation.clips(entityId: string | EntityRef) -> { AnimationClip }
The clips contributing to a body's pose right now, with their playheads and their retarget coverage.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
Returns { AnimationClip } — An array of AnimationClip.
for _, c in animation.clips(hero.id) do print(c.name, c.time, c.matched) end
typed/builtin//modules/api/engine/animation/animation/coverage
animation.coverage(entityId: string | EntityRef) -> (number, number)
How many of a body's bones the clips driving it actually reach.
Returns (matched, total). A clip that retargets onto nothing reads
(0, 50) while its playhead advances; a partial retarget reads its own
count, so 3 of 50 is as visible as none.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
Returns (number, number) — (matched, total).
local m, t = animation.coverage(hero.id); print(m .. "/" .. t)
typed/builtin//modules/api/engine/animation/animation/declare
animation.declare(entityId: string, facts: { [string]: any })
Publish what an animator is running on a body, so the observation names
its clips, playheads and retarget coverage beside the pose the engine
measures. The shipped animators declare through AnimGraph:publish; a
custom animator calls this itself whenever what it runs changes. A clip
that names its sampler (the handle skeleton.bindClip returned) reports
the playhead that sampler last sampled at, and each sample keeps the
declaration current; an animator declaring a clip without its sampler
declares on every frame it runs, since nothing else shows it is still
running. A declaration stands until the animator declares again or calls
animation.forget.
Parameters
entityIdstring— The body the animator drives.facts{ [string]: any }—{ driver, bound, playing, outputKind, failure, clips }, where each clip is{ name, nodeKind, sampler, time, duration, playing, finished, looping, weight, matched, total, unmatched };unmatchedlists the bones the clip leaves at rest that fill a role of the body's retarget profile first.
animation.declare(body.id, { driver = "MyAnimator", playing = true, clips = {} })
typed/builtin//modules/api/engine/animation/animation/forget
animation.forget(entityId: string)
Drop the declaration and the pose evidence the engine holds for one body. An animator calls this when it releases a body, so the observation reports the body as undriven from the next frame.
Parameters
entityIdstring— The body to drop.
animation.forget(body.id)
typed/builtin//modules/api/engine/animation/animation/observe
animation.observe() -> AnimationObservation
Report what the engine is posing right now and why a body is not moving. One read covering every body the engine holds animation state for, each with the pose evidence the engine measured on its armature beside the clips the animator driving it declared. Answers in edit mode as well as play mode.
Returns AnimationObservation — An AnimationObservation.
local a = animation.observe(); print(a.animatingCount, a.riggedBodyCount)
for _, b in animation.observe().bodies do print(b.entity, b.animating, b.reason) end
typed/builtin//modules/api/engine/animation/animation/poseDue
animation.poseDue(entityId: string | EntityRef) -> boolean
Whether the engine evaluates this body's pose this frame. The engine
decides each rigged body's interval once a frame from what the views see
of it, and every shipped animator (AnimGraph:tick, the graphs the engine
runs, AvatarAnimator) evaluates only on the frames this answers true,
carrying the time of the frames between into the next evaluation. A custom
animator does the same: skip the evaluation and keep the delta when this
is false. A body the engine does not schedule answers true.
Parameters
entityIdstring | EntityRef— The skinned body's id, or an EntityRef.
Returns boolean — true on a frame the body is evaluated on.
if animation.poseDue(body.id) then print("evaluated this frame") end
typed/builtin//modules/api/engine/animation/animation/poseRate
animation.poseRate(entityId: string | EntityRef) -> AnimationPoseRate?
How often the engine evaluates a body's pose and why, as an
AnimationPoseRate. Accepts the body or an entity above it, answering for
the first scheduled body beneath. nil when no body there is scheduled.
Parameters
entityIdstring | EntityRef— The body's id, an entity above it, or an EntityRef.
Returns AnimationPoseRate? — An AnimationPoseRate, or nil.
local r = animation.poseRate(hero.id); print(r and r.interval, r and r.reason)
typed/builtin//modules/api/engine/animation/animation/poseRates
animation.poseRates() -> AnimationPoseRates
Every scheduled body's rate in total, with the settings the intervals
are chosen by, as an AnimationPoseRates: how many bodies are evaluated
every frame, how many for each reason, and the share of full-rate
evaluations a frame makes.
Returns AnimationPoseRates — An AnimationPoseRates.
local t = animation.poseRates(); print(t.bodies, t.evaluationShare, t.byReason.offscreen)
typed/builtin//modules/api/engine/animation/animation/ragdoll
animation.ragdoll(entityId: string | EntityRef, opts: (boolean | RagdollOptions)?) -> string
Ragdoll a skinned body: its skeleton is carried by physics bodies that
fall, tumble and pose the mesh, for a death, a knockout, a hit reaction, a
stunt fall or a limp limb. Works on any rigged skeleton: a humanoid (the
built-in avatar and any imported humanoid rig) gets bodies sized for each
body part and anatomical joints (hinged knees and elbows, cones at the
shoulders, hips and neck); any other rig (a quadruped, a bird, a tail, a
robot arm) gets a capsule along every bone and ball joints. The first call
builds the ragdoll on the next frame, false included (its bodies follow
the animation until it is switched on, so its bones can be read and
jointed first); animation.ragdollState reads it back. false hands the
body back to its animation: every bone moves from where the ragdoll left
it to the pose its animation holds over blend seconds (play a get-up
clip on the body as you call it, and the body rises into it; a body
nothing animates goes back to the pose it held when it fell), and the
entity this call names (or the nearest one above it that also holds the
skeleton's bones) is moved to stand the body up where it lies (over the
place the hips lie, turned the way the body lies). true ragdolls it
again. A ragdoll poses the body whatever animates it: a clip player, an
animation graph or a locomotion program.
The options table takes active (default true), limp (bone names: only
those bones and the bones below them go limp while the rest keep
animating), blend (the seconds a bone handed back to its animation takes
to reach it, default 0.5; 0 hands it back in one frame), standUp
(default true; false leaves the entity this call names where it is when
the body is handed back), mass (the whole body's mass in kilograms; by default bodies
weigh 1000 kg per cubic metre of collider, about 120 kg for the built-in
avatar, so pass a person's 60 to 90 kg for a lifelike one) and bones (bone
name -> { shape = "capsule" | "box" | "sphere" | "none", radius, length, size = {x, y, z}, mass, joint = "ball" | "hinge" | "fixed", swing, twist, hinge = {min, max}, strength, damping }, sizes in metres and angles in
degrees). A description different from the last one rebuilds the ragdoll.
On a humanoid a bone is also named by its humanoid role (hips, spine,
chest, neck, head, leftshoulder, leftarm, leftforearm,
lefthand, leftupleg, leftleg, leftfoot and the right ones), so
one description fits every humanoid rig.
Each bone body is the body of that bone's armature entity (its id in
ragdollState), so every Physics call takes it: Physics.addJoint to
hold a hand to a ledge (breakable with breakForce), Physics.applyImpulseAtPoint
for a hit, Physics.getVelocity, Physics.bodyState and Physics.contacts
to measure a fall.
Parameters
entityIdstring | EntityRef— The skinned entity, or any entity above it (a character root).opts(boolean | RagdollOptions)(optional) —true/false, or aRagdollOptionstable.
Returns string — The id of the skinned entity the ragdoll is built on.
animation.ragdoll(enemy.id) -- collapse it
animation.ragdoll(enemy.id, false) -- back to its animation, standing up where it lies
animation.ragdoll(enemy.id, { active = false, blend = 1.2 }) -- a slower rise
animation.ragdoll(hero.id, { limp = { "leftarm" } }) -- one limp arm
animation.ragdoll(dummy.id, { mass = 75, bones = { head = { mass = 5, swing = 30 }, leftleg = { hinge = { -140, 0 } } } })
local hand = animation.ragdollBone(hero.id, "righthand"); Physics.addJoint(hand, ledge, { kind = "ball", breakForce = 3000 })
typed/builtin//modules/api/engine/animation/animation/ragdollBone
animation.ragdollBone(entityId: string | EntityRef, bone: string) -> string?
The entity a ragdoll's bone body answers to, by bone name or, on a
humanoid, by humanoid role (head, righthand, ...): the id to
pass Physics.addJoint, Physics.applyImpulseAtPoint,
Physics.getVelocity, Physics.bodyState, Physics.contacts and every
other Physics call. nil until the ragdoll is built, or when that bone
has no body of its own.
Parameters
entityIdstring | EntityRef— The skinned entity, or any entity above it.bonestring— The bone's name in the skeleton.
Returns string? — The bone body's entity id, or nil.
local head = animation.ragdollBone(dummy.id, "head"); print(Physics.getVelocity(head))
typed/builtin//modules/api/engine/animation/animation/ragdollState
animation.ragdollState(entityId: string | EntityRef) -> RagdollState?
The ragdoll built on a skinned body: whether the simulation drives
it, its total mass, and every bone body with the entity it answers to (the
bone's armature entity), its shape and size in metres, its mass read off
the solver, whether it is simulated, and its joint. built reads false
until the engine has built it (the frame after animation.ragdoll), and
problems names anything the description asked for that the skeleton
could not give. Under multiplayer replication reads which peer simulates
the ragdoll (the owner of the synced entity at or above the body; every
other peer shows it from that peer's bone poses) and what it costs on the
wire.
Parameters
entityIdstring | EntityRef— The skinned entity, or any entity above it.
Returns RagdollState? — A RagdollState, or nil when the body carries no ragdoll.
local r = animation.ragdollState(hero.id); for _, b in r.bones do print(b.bone, b.mass, b.joint and b.joint.kind) end
typed/builtin//modules/api/engine/animation/animation/setPoseRate
animation.setPoseRate(entityId: string | EntityRef, mode: string | number)
Pin how often a body's pose is evaluated, wherever it stands: "exact"
(every frame, for a character whose bones drive gameplay, attachments or
physics off screen as well as on), a number of frames (1 to 120), or
"auto" to return it to the interval the views decide. Applies to every
skinned body at or below the entity, from the next frame. Raises when no
entity at or below it carries a Skeleton, as a character whose model
has not loaded yet: pin it once its body is there.
Parameters
entityIdstring | EntityRef— The body, an entity above it, or an EntityRef.modestring | number—"exact","auto", or frames between two evaluations.
animation.setPoseRate(boss.id, "exact")
typed/builtin//modules/api/engine/animation/animation/setPoseRateSettings
animation.setPoseRateSettings(settings: { [string]: any })
Change how the engine chooses each body's interval, replacing the
fields named (see PoseRateSettings): steps from the largest share of a
view's height down (a visible body takes the first step it spans, and the
last step's interval below them all), offscreenInterval for a body no
view holds, nearDistance in metres within which a body is evaluated
every frame, viewMarginDeg by which each view is widened, and enabled.
Raises naming the field when one cannot apply, and changes nothing then.
Parameters
settings{ [string]: any }— The fields to replace.
animation.setPoseRateSettings({ offscreenInterval = 30 })
typed/builtin//modules/api/engine/animation/animation/whyStill
animation.whyStill(entityId: string | EntityRef) -> (string?, string?)
Why the body on an entity is not animating. Returns nil when it IS
animating, and otherwise one of deactivated, noRiggedSkeleton,
noGraph, clipUnreadable, noOutputNode, retargetPending, retargetMatchedNoRoles,
stopped, finished, paused, poseNotApplied, poseUnchanged — the
nearest cause, so the answer names the thing to change. A second return
carries the animator's own words when it could not build a graph.
An entity the engine holds no animation state for is answered from the
entity itself, in the same order the engine resolves a body it does hold:
one carrying no rigged Skeleton is noRiggedSkeleton, and a rigged one
nothing drives is noGraph. An id no entity carries is neither — the
reason is nil and the detail says so.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
Returns (string?, string?) — (reason, detail).
local why, detail = animation.whyStill(hero.id); if why then print(why, detail) end