AnimationState

Hoisted, observable playback state for a single glTF Animator, created with rememberAnimationState and passed to GltfInstance. It auto-advances on every frame and drives the animator each frame in one of two modes:

Single-track (the convenience path). Set animationIndex and the active clip plays, looping at its length; assigning a new index cross-fades from the outgoing clip over crossFadeDuration. This covers the common "play idle, blend into walk" case without touching the mixer.

Multi-track mixer. Add tracks with rememberAnimationTrack and the state blends them by AnimationTrack.weight every frame — a blend tree (e.g. idle↔walk↔run driven by a speed parameter). While the mixer has tracks it takes precedence and animationIndex is ignored. Filament blends two clips per call, but weighted cross-fades chain, so an arbitrary number of weighted clips compose into one pose.

For an imperative game loop (an animation state machine outside composition), use AnimationMixer directly instead of this hoisted state — see rememberAnimationMixer.

Per-bone masks and additive layers are not expressible — the native animator blends the whole skeleton. For that, or any fully manual control, use GltfInstance's onUpdate and call the Animator directly.

// Single-track with auto cross-fade:
val anim = rememberAnimationState(initialAnimationIndex = idle, initialCrossFadeDuration = 0.25f)
GltfInstance(asset = character, animationState = anim)
anim.animationIndex = walk // cross-fades

// Blend tree — hold both clips and drive the weight from a parameter:
val anim = rememberAnimationState(initialAnimationIndex = null)
rememberAnimationTrack(anim, walkIndex, weight = 1f - speed)
rememberAnimationTrack(anim, runIndex, weight = speed)

Properties

Link copied to clipboard

The animation to play in single-track mode. Assigning cross-fades from the current one; null pauses. Ignored while the mixer has tracks.

Link copied to clipboard

Cross-fade length in seconds applied when animationIndex changes. 0 = hard cut.

Link copied to clipboard

Pauses advancement of every track and the single-track clock while true.

Link copied to clipboard

True while a single-track cross-fade transition is in progress. Read-only.

Link copied to clipboard

Whether the single-track animation wraps at its end (true) or holds the final frame (false).

Link copied to clipboard

The weighted track mixer for the blend-tree path. Add tracks with rememberAnimationTrack; while it has tracks it drives playback and animationIndex is inert.

Link copied to clipboard

Normalized progress (0..1) of the single-track animation. 0 when the clip has no duration.

Link copied to clipboard

Playback rate multiplier for the single-track path (1 = real time, negative = backwards).

Link copied to clipboard
val time: Float

Current playback time of the single-track animation in seconds. Read-only, updates per frame.

Functions

Link copied to clipboard
fun seek(time: Float)

Resets the single-track clock to time seconds.