The Animator
A character rarely plays one clip. It idles, starts walking, breaks into a run, jumps, lands. The Animator decides which clip plays and blends smoothly from one to the next. This page covers state machines, blend trees, driving them from a script or a UI button, playing clips made for another character, and event markers.
Everything here happens in Play mode and in your shipped game. While you edit, the Timeline owns the pose.
State machines
A state machine is a small set of states joined by transitions. Each state plays something (one clip, or a blend of several), and each transition says when to move from one state to another and how long to fade. The machine is saved as a .animsm file next to your clips and picked in the Animator's State machine field.
Making one
- Select a model that already has clips.
- Switch the stage to Logic mode (or open the State Machine panel).
- Press Create State Machine. This writes a starter
.animsmbeside the clips with one state per clip, the default clip as the entry state, and no transitions yet, and assigns it to the Animator. If the file already exists, it is assigned rather than overwritten. - Add the transitions you need, then Save.
The panel has two columns, States and Transitions, each with its own add button.
States
Each state has a name, what it plays, a speed and a loop switch. One state is the entry state: it starts as soon as the game starts. An Animator with a state machine leaves the choice of clip to the machine, so its Default clip does not also play.
A state's motion is one of:
| Motion | What the state plays |
|---|---|
| Clip | One clip, picked by its slot name |
| 1D blend | Several clips spread along one number, such as speed |
| 2D blend | Several clips placed on a flat map of two numbers, such as sideways and forward movement |
Transitions
A transition goes from one state to another, with a blend time (how long the fade takes) and a condition:
| Condition | Moves on when |
|---|---|
| Float > | A number parameter is above a value |
| Float < | A number parameter is below a value |
| Bool true / Bool false | A true/false parameter has that value |
| Trigger | A trigger parameter is fired (it resets itself afterwards) |
| Time >= | The current state has played for at least this many seconds |
| Always | Straight away |
Parameters
Parameters are the values transitions and blends read: numbers (like speed), true/false switches (like grounded) and triggers (like jump). The Parameters panel lists them for the selected character, grouped into floats, bools and triggers. You can add one, change a value, or press a trigger's fire button, and the machine reacts right away, so you can try transitions without playing the game.
Blend trees
A blend state mixes clips by a parameter, which is how a walk turns smoothly into a run as the character speeds up.
1D blend
Each entry is a clip at a threshold along one parameter. Use real units if you like: with idle at 0, walk at 1.5 and run at 4, feed in the character's speed in metres per second. Between two thresholds, their clips share the weight; past either end, the end clip plays alone.
2D blend
Each entry is a clip at a point (x, y) on a plane of two parameters, typically sideways and forward movement for a character that strafes. Standing exactly on an entry plays that clip alone. Put idle at the middle and the walks around it.
In the panel, switching a state's motion from Clip to a blend keeps its clip as the first entry. A blend state shows its parameter name (or two), one row per entry, and Add entry under them.
How blended clips play together
- Clips of different lengths are kept in step, so a walk and a run blended together plant their feet at the same time.
- The state's speed scales the whole blend.
- Only the most heavily weighted clip fires its event markers, so a blend of walk and run does not play two footsteps.
Driving the Animator
From a Rust script
A Rust script on the character sets parameters by sending AnimationCommands:
use bevy::prelude::*;
use renzora::{AnimationCommand, AnimationCommandQueue, ScriptCtx};
fn update(ctx: &mut ScriptCtx) {
let me = ctx.entity();
let Some(keys) = ctx.get_resource::<ButtonInput<KeyCode>>() else { return };
let speed = match (keys.pressed(KeyCode::KeyW), keys.pressed(KeyCode::ShiftLeft)) {
(true, true) => 4.0,
(true, false) => 1.5,
_ => 0.0,
};
let jump = keys.just_pressed(KeyCode::Space);
if let Some(mut queue) = ctx.get_resource_mut::<AnimationCommandQueue>() {
queue.push(AnimationCommand::SetParam { entity: me, name: "speed".into(), value: speed });
if jump {
queue.push(AnimationCommand::Trigger { entity: me, name: "jump".into() });
}
}
}
renzora::script!(update);
SetBoolParam sets a true/false parameter the same way. The full list of commands is on Animating.
From a UI button, with no script
A button in your game UI can drive an Animator directly through its on_press, naming the entity and the parameter:
on_press | Does |
|---|---|
anim:hero.cheer | Fires the cheer trigger on the entity named hero |
anim:door.open=true | Sets the open bool on door |
anim:hero.speed=2.5 | Sets the speed float on hero |
Separate several actions with commas: on_press="anim:hero.cheer, play_sound" fires the trigger and also tells your scripts about play_sound.
Fades between clips
Any change of clip fades over the Animator's Blend time (in seconds), and a transition fades over its own blend time. A Crossfade command from a script picks its own fade length.
Playing clips made for another character
Clips find bones by name, so a clip plays on any skeleton whose bones are named the same way. That is enough when both skeletons also rest the same way. A clip made on a skeleton that stands differently (an A-pose against a T-pose) or has other proportions needs to be retargeted.
The engine does this for you when it can. Importing a rigged model writes its rest pose as animations/<model>.skel beside its clips. When a model's clips are found (dropping it into the scene, or Scan for clips), any clip that belongs to another model's .skel in the same folder is marked as coming from that skeleton, and is fitted to yours when it loads:
- each bone's rotation is carried over as a change from its rest pose, so a raised arm stays a raised arm;
- the hips' movement is scaled by the difference in leg length, so a shorter character does not slide;
- other bones keep your character's own proportions.
Bones that only one of the skeletons has simply play by name as before.
So the everyday workflow for an animation pack is: put the pack's files in the same animations/ folder as your character's clips, import them, and press Scan for clips on the character.
Event markers
Markers (see Animating) fire for every clip that is playing, with bones or without:
- each marker fires once every time playback passes it, including when a loop wraps round, and a marker at time 0 fires when the clip starts;
- a clip played faster, slower or backwards fires its markers in the order it reaches them;
- jumping the playback time does not fire the markers it skips, and a paused clip fires nothing;
- a clip faded out to nothing fires nothing.
Layers and root motion
The Animator can also stack layers on top of the base motion (a wave on the upper body while the legs keep walking) and take root motion from a clip (move the character as far as its feet travel). The editor shows an Animator's layers in the Animation panel, and scripts drive them with PlayOnLayer, StopLayer and SetLayerWeight, but there are no fields for setting up layers or root motion in the Inspector yet.
Next
- Animating: clips, the Timeline and keying.
- Rigging and Posing: skeletons, faces and IK.