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.
Before you start
Section titled “Before you start”- 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
onandemit.
How a timeline is built
Section titled “How a timeline is built”- 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.
Properties
Section titled “Properties”| 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.
Interpolation
Section titled “Interpolation”linearmoves 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.smoothcurves through the keys. Use it for cameras and anything that should ease through its keys.stepholds each key’s value until the next key.booleanandstringtracks always step.
Playing layers
Section titled “Playing layers”| Call | What it does |
|---|---|
timeline. |
The layer name; undefined when there is none, when the component is off, and in the editor. |
timeline. |
Every layer as one: each call goes to all of them, and it is playing while any is. |
layer. |
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, and put back what it animated to its values from before it played. |
layer.pause(), layer. |
Freeze it where it is; carry it on. |
layer. |
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. |
Play every layer at speed, at once, from where they are. Same as set. |
timeline. |
The timeline’s THREE., read-only; undefined until a layer first plays. Never call its update(). |
timeline. |
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
repeatplays 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
fadeto crossfade them. - Speed changes are live.
setSpeedrebuilds nothing; the layers play on at the new pace. - Prop changes restart. Changing the
layersprop 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.
Signal keys
Section titled “Signal keys”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
repeatlayer sends its keys again each time it wraps; apingponglayer sends them on its way back too. seeksends 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.
Events
Section titled “Events”The timeline sends these through the Signal Emitters on its entity, each with { layer }:
| Event | EventType |
When |
|---|---|---|
Animation |
Event |
A layer starts playing. |
Animation |
Event |
A layer is stopped. |
Animation |
Event |
A repeating play wraps. |
Animation |
Event |
A once layer reaches its end. |
Animation |
Event |
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.
Examples
Section titled “Examples”1. Build a timeline from code
Section titled “1. Build a timeline from code”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.
#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' });}A gem hovers up and down and spins for ever on an Animation Timeline that a Behavior script builds in code, with a smooth pingpong layer and a linear repeating one.
Watch the gem hover and spin. Drag to orbit the camera, scroll to zoom.
- Keys are in local space, so the script copies the entity’s current position into the first key.
hoverusessmoothinterpolation andpingpong, so it eases up and back down forever.spinturns a full circle (M_TAU, 2π radians) in 4 seconds withlinearinterpolation and wraps withrepeat, giving a steady rotation.- The two layers animate different props, so they play together without blending.
Snippets
Section titled “Snippets”1. Open a door when it is clicked
Section titled “1. Open a door when it is clicked”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'.
#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::selectevent 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.playingstaystruewhile the door swings, so clicks during the swing are ignored.- A
oncelayer 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').
#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.timeis the key’s time. emit('fx/confetti')passes the cue on to any other script or graph listening for it.- The
finishedevent comes through the stage’s Signal Emitter;event.data.layertells which layer finished. - The script plays
showitself, so the timeline does not needautoplay.
3. Slow motion and scrubbing
Section titled “3. Slow motion and scrubbing”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.
#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();}setSpeedchanges every layer’s pace at once; nothing restarts.- While an arrow key is held, the script pauses the layer and seeks it.
seekon a paused layer shows the pose and stays there. - Space resumes playback from the scrubbed point.
seeksends none of the signal keys it skips, so scrubbing does not fire cues.
Common mistakes
Section titled “Common mistakes”- Expecting a fade by default. Timeline layers start at once; pass
fadeto blend. - Expecting
repeatto stick. Each play says how it repeats. A laterplay()withoutrepeatplays 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)isundefinedin 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.layertoo late. One Signal Emitter forwards the events of every layer; always check which layer an event is about.