Skip to content

Animation Timeline

Updated

The Animation Timeline component (comp-animation-timeline) animates the entity it is on: its position, rotation, scale and visibility, along keyframes you author. It can also send bus signals at set moments through signal keys. Use it for authored motion: a door swinging open, a camera fly-through, a light sweeping a stage, a panel sliding in.

Almost every entity takes it: models and primitives, lights, cameras, groups, UI panels, text, images, video, audio and logic entities. Everything a timeline knows lives in its props, which the editor’s timeline tool writes and a script can also write. A script mostly plays, pauses, seeks and stops its layers, and reacts to what they send.

  • Scripts reach the component with getComponent(AnimationTimelineComponent). See Components.
  • Timeline layers use the same layer calls as model clips; the Animation Clip page introduces them.
  • The timeline’s events (play, stop, repeat, finished) reach scripts through a Signal Emitter on its entity. Its signal keys do not need one: they go straight onto the bus. See Scripting for on and emit.
  • A timeline holds layers.
  • A layer is a set of tracks that play together, with its own time and weight. Layers play and stop independently, and each play says how it repeats.
  • A track animates one prop of the entity through keys.
  • A key is a value at a time, in seconds from the start of the layer.

Keyframes are like the poses of a flip book: you set the important ones, and the timeline fills in the motion between them according to the track’s interpolation.

Prop Type Default Description
autoplay boolean false Play layer as the entity starts, in play. An enabled Animation Graph on the entity overrides it.
repeat 'once' | 'repeat' | 'pingpong' 'once' How the autoplay repeats. Plays from scripts and graph states say their own.
layer string '' The layer autoplay plays, by name. Empty, the first enabled layer.
speed number 1 Playback speed of every layer, from 0 to 100: 2 plays twice as fast, 0 holds every layer where it is.
layers array of layers [] Its layers.
Field Type Default Description
name string required Unique within the timeline. Scripts, events and graphs name the layer by it.
enabled boolean true Off, the layer is not built and never plays.
locked boolean false Locks the layer against editing in the timeline tool. No effect at runtime.
weight number 1 Its relative share, from 0 to 1000, when other layers animate the same prop.
tracks array of tracks [] Its tracks.
Field Type Default Description
prop string required The prop it animates: position, rotation, scale, visible or signal.
type string required The prop’s type: vector for position and scale, rotation, boolean for visible, string for signal.
enabled boolean true Off, the track contributes no values or signals.
interpolation 'linear' | 'smooth' | 'step' 'linear' How values move between keys.
color string '' Its colour in the timeline tool. No effect at runtime.
keys array of { time, value } required Its keys, time in seconds from 0.
prop A key’s value
position [x, y, z], local, in metres
rotation Euler [x, y, z] in radians, local
scale [x, y, z]
visible true or false: shown or hidden for this session only, never saved
signal a bus signal name, sent as playback passes the key

Structurally bad data (an unknown prop, two layers with one name, a key without a finite time) is refused when the props are set, with a TypeError.

  • linear moves in a straight line between keys. A rotation turns the shortest way, and a turn of more than half a circle is split so a full 0 to 2π spin plays in full.
  • smooth curves through the keys. Use it for cameras and anything that should ease through its keys.
  • step holds each key’s value until the next key. boolean and string tracks always step.
Call What it does
timeline.layer(name) The layer name; undefined when there is none, when the component is off, and in the editor.
timeline.layer() Every layer as one: each call goes to all of them, and it is playing while any is.
layer.play({ fade?, repeat?, repeatCount? }) Play from the start. repeat: 'once' (the default), 'repeat' or 'pingpong'. repeatCount: how many times a repeating play plays in all; Infinity (the default) is forever.
layer.stop({ fade? }) Stop, and put back what it animated to its values from before it played.
layer.pause(), layer.resume() Freeze it where it is; carry it on.
layer.seek(time) Move to time seconds, held within the layer’s length, shown at once. A playing layer plays on from there; one not playing waits there, paused, until resume().
layer.playing false while paused, fading out, once stopped, or once its play reached its end.
timeline.setSpeed(speed) Play every layer at speed, at once, from where they are. Same as setProps({ speed }).
timeline.mixer The timeline’s THREE.AnimationMixer, read-only; undefined until a layer first plays. Never call its update().
timeline.observe(listener) Call listener() each time the layers are rebuilt; returns a function that stops listening.

How playback behaves:

  • No fade by default. A timeline layer plays at once when you give no fade, unlike a clip.
  • Each play repeats as it says. The next play without repeat plays once.
  • Stop restores. Stopping a layer puts what it animated back. Switching the entity off, switching its scene away or removing the timeline stops its layers.
  • Blending. Two layers animating one prop at once mix by their weights. Play one layer in and another out with the same fade to crossfade them.
  • Speed changes are live. setSpeed rebuilds nothing; the layers play on at the new pace.
  • Prop changes restart. Changing the layers prop stops every layer and puts the values back, then autoplay plays again from the start.
  • Local only. The timeline writes onto the entity itself: nothing is saved or sent over the network. Each client plays its own.

A signal track’s keys go on the bus as playback passes them, each under its own signal name, with data { layer, time }. Any script’s on(name, …) or any Animation Graph transition listening for the name hears them; no Signal Emitter is needed.

  • Every key passed goes, in order, even several in one long frame.
  • A repeat layer sends its keys again each time it wraps; a pingpong layer sends them on its way back too.
  • seek sends none of the keys it skips. Pausing or stopping sends none.
  • The editor, including its preview, sends none.

Signal keys are how you chain animations: put a key at the end of one layer and let a graph transition or a script play the next.

The timeline sends these through the Signal Emitters on its entity, each with { layer }:

Event EventType When
AnimationTimeline::play EventType.AnimationTimeline.Play A layer starts playing.
AnimationTimeline::stop EventType.AnimationTimeline.Stop A layer is stopped.
AnimationTimeline::repeat EventType.AnimationTimeline.Repeat A repeating play wraps.
AnimationTimeline::finished EventType.AnimationTimeline.Finished A once layer reaches its end.
AnimationTimeline::signal EventType.AnimationTimeline.Signal A signal key is passed; data { layer, time }.

A Signal Emitter filters by event type, not by layer: on a timeline with several layers, read event.data.layer.

A script can create a timeline with its layers and play it, which is useful for procedurally placed objects. This one makes its entity hover and spin forever.

HoverSpin.jx
#pragma lifecycle(startup)
function startup() {
const p = self.parent.position;
const timeline = new AnimationTimelineComponent({
layers: [
{
name: 'hover',
tracks: [
{
prop: 'position', type: 'vector', interpolation: 'smooth',
keys: [
{ time: 0, value: [p.x, p.y, p.z] },
{ time: 1, value: [p.x, p.y + 0.3, p.z] },
],
},
],
},
{
name: 'spin',
tracks: [
{
prop: 'rotation', type: 'rotation', interpolation: 'linear',
keys: [
{ time: 0, value: [0, 0, 0] },
{ time: 4, value: [0, M_TAU, 0] },
],
},
],
},
],
});
self.parent.addComponent(timeline);
timeline.layer('hover')?.play({ repeat: 'pingpong' });
timeline.layer('spin')?.play({ repeat: 'repeat' });
}
  • Keys are in local space, so the script copies the entity’s current position into the first key.
  • hover uses smooth interpolation and pingpong, so it eases up and back down forever.
  • spin turns a full circle (M_TAU, 2π radians) in 4 seconds with linear interpolation and wraps with repeat, giving a steady rotation.
  • The two layers animate different props, so they play together without blending.

The door has a timeline with an open layer authored in the editor, a Selectable so it can be clicked, and a Signal Emitter with signal: 'door'.

DoorToggle.jx
#pragma lifecycle(startup)
const timeline = self.getComponent(AnimationTimelineComponent);
let open = false;
function startup() {
on('door', (event) => {
if (event.eventType !== EventType.Selectable.Select) return;
findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again
const layer = timeline.layer('open');
if (!layer || layer.playing) return; // missing, or still moving
if (open) layer.stop({ fade: 0.6 });
else layer.play();
open = !open;
});
}
  • The click arrives as a Selectable::select event through the door’s Signal Emitter.
  • The script fetches the layer at click time, so it always gets the current one, even after the layers change.
  • layer.playing stays true while the door swings, so clicks during the swing are ignored.
  • A once layer holds its last frame, so the door stays open. stop({ fade: 0.6 }) blends back to the closed pose over 0.6 seconds, because stopping restores the values from before the layer played.

2. React to signal keys and finished layers

Section titled “2. React to signal keys and finished layers”

A stage show has a show layer with signal keys show/lights and show/confetti. A script elsewhere in the scene reacts to them, and to the layer finishing (through a Signal Emitter on the stage with signal: 'stage').

ShowDirector.jx
#pragma lifecycle(startup)
function startup() {
const stage = findEntity('Stage');
const timeline = stage.getComponent(AnimationTimelineComponent);
on('show/lights', (event) => log('Lights cue at', event.data.time, 's'));
on('show/confetti', () => emit('fx/confetti'));
on('stage', (event) => {
if (event.eventType === EventType.AnimationTimeline.Finished && event.data.layer === 'show') {
log('Show over, bowing');
timeline.layer('bow')?.play();
}
});
timeline.layer('show')?.play();
}
  • Signal keys go straight onto the bus under their own names, so on('show/lights', …) hears them with no emitter. event.data.time is the key’s time.
  • emit('fx/confetti') passes the cue on to any other script or graph listening for it.
  • The finished event comes through the stage’s Signal Emitter; event.data.layer tells which layer finished.
  • The script plays show itself, so the timeline does not need autoplay.

The timeline’s speed and seek give a script full control over playback. Here 1 and 2 set the speed, and the arrow keys scrub through a flythrough layer.

TimelineScrub.jx
#pragma lifecycle(startup, update)
const timeline = self.getComponent(AnimationTimelineComponent);
let time = 0;
function startup() {
timeline.layer('flythrough')?.play({ repeat: 'repeat' });
}
function update(dt) {
const layer = timeline.layer('flythrough');
if (!layer) return;
if (Input.keyboard.isKeyReleased(Key.Digit1)) timeline.setSpeed(0.25);
if (Input.keyboard.isKeyReleased(Key.Digit2)) timeline.setSpeed(1);
const left = Input.keyboard.isKeyPressed(Key.ArrowLeft);
const right = Input.keyboard.isKeyPressed(Key.ArrowRight);
if (left || right) {
time = Math.max(0, time + (right ? dt : -dt) * 2);
layer.pause();
layer.seek(time);
}
if (Input.keyboard.isKeyReleased(Key.Space)) layer.resume();
}
  • setSpeed changes every layer’s pace at once; nothing restarts.
  • While an arrow key is held, the script pauses the layer and seeks it. seek on a paused layer shows the pose and stays there.
  • Space resumes playback from the scrubbed point.
  • seek sends none of the signal keys it skips, so scrubbing does not fire cues.
  • Expecting a fade by default. Timeline layers start at once; pass fade to blend.
  • Expecting repeat to stick. Each play says how it repeats. A later play() without repeat plays once.
  • Keeping a layer object. A layer belongs to the layers built at that time; after the layers change it does nothing. Fetch it with layer(name) when you need it.
  • Testing in the editor. layer(name) is undefined in the editor and signal keys are not sent there. Use Play or Preview.
  • Animating a dynamic physics body. The body does not follow. Use a kinematic body or none.
  • Autoplay that never starts. An enabled Animation Graph on the entity takes over: play the layer from a graph state.
  • Reading event.data.layer too late. One Signal Emitter forwards the events of every layer; always check which layer an event is about.