Skip to main content
Version: 0.16.0

Animation

Description​

Plays an agent's animations. Everything sits on a playback driver, which is the only part that touches Unity's animation system. The shipped driver builds a PlayableGraph per agent, with a locomotion blend at the bottom and one layer per entry in the profile above it. See Animation Layers for how the layers are authored.

Reach an agent's animation through its applicator service:

csharp
var animation = agent.GetApplicatorService().GetAnimationService();

IAnimationService​

NameParametersReturn TypeDescription
SetupGameObject parent, IDynamicService dynamicService = nullboolBinds the driver to the agent and hands it to the dynamic service. False if no Animator was found.
SetCoreSetICoreAnimationSet set, string groupName = nullvoidReplaces the idle, move and rotate clips. The group name is only for the inspector readout.
UpdateLocomotionLocomotionState updatevoidMerges the update over the held state and pushes it to the driver. Absent fields are left as they were.
GetLocomotionN/ALocomotionStateThe merged locomotion state.
Tickfloat deltaTimevoidAdvances blends. Called from the agent's LateUpdate.
GetDriverN/AIAnimationPlaybackDriverThe driver underneath.
GetDynamicServiceN/AIDynamicServiceThe service that plays action sequences.
CaptureDebugStateN/AAnimationDebugStateWhat is playing, for the inspector.
CaptureSnapshotN/AAnimationPlaybackSnapshotLocomotion state and every layer's clip, time, weight and held flag, for saving.
RestoreSnapshotAnimationPlaybackSnapshot snapshotboolPuts a snapshot back. False for null.
DisposeN/AvoidStops playback and destroys the graph. Called when the agent is destroyed.

LocomotionState​

What the agent's legs are doing. Every field is optional, and UpdateLocomotion leaves an absent field alone, so movement, looking and the per-frame speed tick can each write only the part they own.

FieldTypeDescription
Movingbool?Whether the agent is walking.
Speedfloat?Normalised speed, 0 to 1. Blends idle against move.
TurnRatefloat?Degrees per second, signed. Blends the rotate clip in when still.

IDynamicService​

Plays a sequence of clips on a layer — an action's start, middle and end.

NameParametersReturn TypeDescription
SetupIAnimationPlaybackDriver driverboolGives it the driver to play through.
RunAnimationClip[] clips, LENGTH_ENFORCEMENT_MODE enforcement = FREE, bool ignorePause = false, bool holdLastPose = falsevoidPlays the clips in order on the profile's first layer.
RunAnimationClip[] clips, string layerName, LENGTH_ENFORCEMENT_MODE enforcement = FREE, bool ignorePause = false, bool holdLastPose = falsevoidThe same, on a named layer. An unknown name falls back to the first layer and warns once.
IsRunningN/AboolWhether a sequence is still playing.
CurrentTimeLeftN/Afloat?Seconds left in the sequence, or null when nothing is playing.
GetCurrentTimeN/AfloatSeconds since the sequence started.
StopN/AvoidStops the sequence.

With holdLastPose, the layer keeps the last clip's final frame showing after the sequence ends, until something else plays on it. Without it, the layer fades back out.

IAnimationPlaybackDriver​

The seam between the services above and Unity. It deals only in clips, layer names and weights. The shipped driver is PlayableAnimationDriver; AnimationService takes any driver, so a different playback scheme means a different driver and nothing else.

NameParametersReturn TypeDescription
BindGameObject rootboolFinds the Animator and builds the graph. Takes any assigned controller off and restores it on Dispose.
SetLocomotionClipsAnimationClip idle, AnimationClip move, AnimationClip rotatevoidReplaces the core clips, crossfading from the previous set.
SetLocomotionLocomotionState statevoidSets the idle, move and rotate weights from the state.
ResolveLayerstring layerNameAnimationLayerHandleThe layer with that name. Empty gives the first layer; unknown gives the first and warns once.
PlayAnimationLayerHandle layer, AnimationClip clip, float fadeSecondsvoidCrossfades the clip in on the layer and fades the layer up. 0 uses the layer's own fade.
HoldAnimationLayerHandle layervoidFreezes the layer on its current frame and keeps it up.
ReleaseAnimationLayerHandle layer, float fadeSecondsvoidFades the layer out. Its clips are dropped once it reaches zero.
SetPausedbool pausedvoidFreezes every layer as it is, and lets it go again.
Tickfloat deltaTimevoidAdvances every fade.
CapturePlaybackAnimationPlaybackSnapshot snapshotvoidWrites each layer's state into the snapshot.
RestorePlaybackAnimationPlaybackSnapshot snapshotvoidPuts each layer back, matched by layer name and clip name.
DisposeN/AvoidDestroys the graph.

AgentAnimationProfile​

The layer stack, as a ScriptableObject. Locomotion is always the bottom layer and is not listed.

NameParametersReturn TypeDescription
layersN/AAnimationLayerDefinition[]The layers, in order from just above locomotion upwards.
LayerCountN/AintHow many layers.
GetLayerint indexAnimationLayerDefinitionThe layer at that position, or null.
IndexOfstring layerNameintThe layer with that name, ignoring case, or -1.

AnimationLayerDefinition​

FieldTypeDescription
namestringWhat animation groups use to pick the layer.
maskAvatarMaskBones the layer drives. Null drives the whole body.
additiveboolAdd on top of the layers below rather than replace them.
weightfloatWeight the layer reaches when something is playing on it.
fadeSecondsfloatSeconds to blend the layer in and out. 0 uses Layer Blend from module settings.

AnimationDebugState​

Returned by CaptureDebugState and shown in the agent inspector's Animation section.

FieldTypeDescription
coreGroupNamestringThe core animation group the agent is using.
weightsLocomotionWeightsIdle, move and rotate weights, which sum to one.
layersLayerReadout[]Per layer: name, mask, additive, weight, clip, time and held.