NEOLearn

Animation clips

Build an AnimationClip in code from curves that target component fields, choose which entities it animates, and fire events at set times.

Updated October 20, 2026

On this page

An AnimationClip is an asset that holds curves, each one changing one property of one entity over time, and events that fire at given times. Clips usually come from glTF files, but you can build them in code for doors, platforms, UI and anything else that moves on a fixed path.

A clip in code#

This clip moves an entity around a square in four seconds and loops:

src/main.rs
use neo::{
    animation::{animated_field, AnimatedBy, AnimationTargetId},
    prelude::*,
};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
    mut clips: ResMut<Assets<AnimationClip>>,
    mut graphs: ResMut<Assets<AnimationGraph>>,
) {
    commands.spawn((Camera3d::default(), Transform::from_xyz(0.0, 4.0, 6.0).looking_at(Vec3::ZERO, Vec3::Y)));
    commands.spawn((PointLight::default(), Transform::from_xyz(0.0, 4.0, 0.0)));

    // 1. the clip: one curve on Transform::translation of the entity named "platform"
    let name = Name::new("platform");
    let target = AnimationTargetId::from_name(&name);
    let mut clip = AnimationClip::default();
    clip.add_curve_to_target(
        target,
        AnimatableCurve::new(
            animated_field!(Transform::translation),
            UnevenSampleAutoCurve::new([0.0, 1.0, 2.0, 3.0, 4.0].into_iter().zip([
                Vec3::new(1.0, 0.0, 1.0),
                Vec3::new(-1.0, 0.0, 1.0),
                Vec3::new(-1.0, 0.0, -1.0),
                Vec3::new(1.0, 0.0, -1.0),
                Vec3::new(1.0, 0.0, 1.0), // same as the first key, so the loop is seamless
            ]))
            .expect("valid keyframes"),
        ),
    );

    // 2. a graph with the clip, and a player that loops it
    let (graph, node) = AnimationGraph::from_clip(clips.add(clip));
    let mut player = AnimationPlayer::default();
    player.play(node).repeat();

    // 3. the animated entity: it is also the player here
    let platform = commands
        .spawn((
            Mesh3d(meshes.add(Cuboid::new(1.0, 0.2, 1.0))),
            MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
            name,
            AnimationGraphHandle(graphs.add(graph)),
            player,
        ))
        .id();
    commands.entity(platform).insert((target, AnimatedBy(platform)));
}

Targets#

A curve doesn't point at an entity directly. It points at an AnimationTargetId, and every entity the clip should move carries that id plus AnimatedBy(player), the entity with the AnimationPlayer. That way one clip can play on many copies of the same model.

ConstructorMakes an id from
AnimationTargetId::from_name(&name)One Name.
AnimationTargetId::from_names([root, child, grandchild].iter())The path of names from the player's entity down the hierarchy. glTF files use this for bones.

The player and the targets can be the same entity, as above, or a parent and its descendants.

Curves#

A curve is a property plus the values over time:

PartOptions
The propertyanimated_field!(Component::field) for any field of a component that derives Reflect, such as Transform::translation, Transform::rotation or UiTransform::scale. For anything else, implement AnimatableProperty yourself; the animated_ui example animates a text colour this way.
The valuesAny curve from the engine's curve library: UnevenSampleAutoCurve (keys at the times you give), SampleAutoCurve (evenly spaced keys), EasingCurve (from a start to an end value with an easing function), or a curve made with reparametrize_linear, ping_pong, chain and the other curve adaptors. See Curves and easing.

The values must be a type the engine can blend: f32, f64, Vec2, Vec3, Vec4, Quat, Rot2, bool, Transform, and the colour types Srgba, LinearRgba, Laba, Oklaba and Xyza.

A clip's duration is its longest curve. A shorter curve holds its last value until the clip ends; if parts of a model should loop at different rates, use separate clips. clip.set_duration(seconds) makes a clip longer than its curves, which is useful when the last thing in it is an event.

Events#

A clip can trigger events while it plays. Derive AnimationEvent, add the event at a time, and observe it:

Rust
use neo::animation::AnimationEvent;

#[derive(AnimationEvent, Clone)]
struct Footstep {
    loud: bool,
}

fn add_steps(clip: &mut AnimationClip, left_foot: AnimationTargetId) {
    clip.add_event(0.5, Footstep { loud: false });                    // on the player's entity
    clip.add_event_to_target(left_foot, 1.0, Footstep { loud: true }); // on the foot's entity
}

fn on_footstep(step: On<Footstep>, transforms: Query<&GlobalTransform>) {
    if let Ok(at) = transforms.get(step.trigger().target) {
        info!("step at {} (loud: {})", at.translation(), step.loud);
    }
}

// app.add_observer(on_footstep);

add_event_fn(time, |commands, entity, time, weight| { .. }) runs a closure instead of triggering an event. Events fire each time playback passes their time, including on every loop.

Examples: cargo run --example animated_transform, animation_events, animated_mesh_events and animated_ui.

Next steps#