Lottie
Updated
A Lottie vector animation surface.
- Type
ent-lottie- Script class
LottieEntity- Family
- Media
Overview
Section titled “Overview”A Lottie entity plays a Lottie animation: a vector animation saved as JSON, made in a motion design tool. It suits animated icons, loaders, badges, confetti and interface flourishes. The animation is drawn into a texture off the main thread at the resolution you choose, so it stays crisp without slowing the world down.
Like a GIF, it plays only while it can be seen: in play while its entity is enabled and shown, and in the editor only while the entity is selected. A play/pause pill is available but off by default.
Pick a sibling when it fits better: an Image GIF when you only have a GIF file, a Video for filmed footage with sound, or an Image SVG for a still vector drawing.
The props that matter most, on its Lottie component (LottieComponent in scripts):
src: the Lottie JSON file, as a URL or an asset from your project.autoplayandrepeat: start once decoded, and loop (repeat) or stop on the last frame (once, which sendsLottie::end).speed: the playback rate, above 0 and up to 16.maxFps: the most frames per second it re-draws, 1 to 60.quality: the drawing resolution. Higher is sharper and costs more per frame; changing it reloads the animation.width,height,opacityandcolor: the plane’s size in metres, its fade and its tint. Lottie does not supportsizing.
Scripts control playback with play() and pause().
Set it up
Section titled “Set it up”- Add a Lottie entity to the scene and name it, such as
Confetti. - Set its
srcto a Lottie JSON file, andwidthandheightto match the animation’s shape. - Choose
repeat; for a one-off effect setonceand turnautoplayoff so a script starts it. - Keep
qualityat 1 unless the animation fills much of the view. - Add a Signal Emitter to hear
Lottie::endand the other events in scripts.
Examples
Section titled “Examples”Play on demand
Section titled “Play on demand”Start a one-shot animation when a signal arrives.
#pragma lifecycle(startup)
// Scene: a Lottie entity "Badge" with repeat: once and autoplay off.let badge;
function startup() { badge = findEntity('Badge').getComponent(LottieComponent); on('badge/earned', () => badge.play());}How it works:
getComponent(LottieComponent)reaches the animation.play()starts it; withrepeat: 'once'it stops on its last frame.
Confetti when a goal is reached
Section titled “Confetti when a goal is reached”Show confetti once, then switch the entity off when it ends.
#pragma lifecycle(startup)
// Scene: a Lottie entity "Confetti", saved disabled, with repeat: once// and a Signal Emitter on the signal 'confetti'.let entity;let lottie;
function startup() { entity = findEntity('Confetti'); lottie = entity.getComponent(LottieComponent);
on('goal/reached', () => { entity.setEnabled(true); lottie.play(); });
on('confetti', (event) => { if (event.eventType === EventType.Lottie.End) entity.setEnabled(false); if (event.eventType === EventType.Lottie.Error) log('Confetti failed:', event.data.message); });}How it works:
- The entity is saved disabled so it is not drawn before the goal; enabling it and calling
play()starts the effect. Lottie::endarrives when aonceanimation reaches its last frame; the script switches the entity off.Lottie::errorcarries amessagewhen the file cannot load or decode.
A loader that follows a task
Section titled “A loader that follows a task”Play a spinner faster while waiting, and fade it out when the work is done.
#pragma lifecycle(startup)
// Scene: a Lottie entity "Loader" (repeat, autoplay on), saved disabled.// Other scripts emit 'task/start' and 'task/done'.let entity;let loader;
function startup() { entity = findEntity('Loader'); loader = entity.getComponent(LottieComponent);
on('task/start', () => { loader.setProps({ opacity: 1, speed: 1.5 }); entity.setEnabled(true); loader.play(); });
on('task/done', async () => { await Tween.value(1, 0, (v) => loader.setProps({ opacity: v }), { duration: 0.3 }); loader.pause(); entity.setEnabled(false); });}How it works:
speedandopacityapply to the running animation without reloading it.Tween.valuefadesopacityfrom 1 to 0; awaiting it waits for the fade to end.- Pausing and disabling the entity stops all work: a hidden animation draws no frames.
- Changing
srcorqualityreloads the animation;speed,repeat,opacityand the other props apply to the one running. play()sets what you want, but a hidden or disabled entity still does not animate; it starts when shown.
Components
Section titled “Components”What a new Lottie is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.
| Component | Type | Role | Per entity | What it does |
|---|---|---|---|---|
| Layer | comp-layer |
Required | One | Puts the entity on a render/raycast layer so cameras and rays can include or skip it. |
| Lock | comp-lock |
Required | One | Editor-only flag that stops the entity from being selected or moved. |
| Enable | comp-enable |
Required | One | Turns the entity and its children on or off: hides them and stops their behavior. |
| Transform | comp- |
Required | One | Position, rotation and scale of the entity, with optional editor-only per-axis locks. |
| Lottie | comp-lottie |
Required | One | A Lottie vector animation surface. |
You can also add 16 optional components, such as Animation Graph, Animation Timeline, Attribution, Billboard, Enable On Signal, Follow Target.
The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).
| Prop | Default | Range |
|---|---|---|
repeat |
"repeat" |
|
width |
1 |
0 ≤ x ≤ 10000 |
height |
1 |
0 ≤ x ≤ 10000 |
color |
"#ffffff" |
|
zoom |
1 |
0. |
grayscale |
0 |
0 ≤ x ≤ 1 |
opacity |
1 |
0 ≤ x ≤ 1 |
projection |
"planar" |
|
side |
"double" |
|
maxFps |
30 |
1 ≤ x ≤ 60 |
autoplay |
true |
|
speed |
1 |
0 < x ≤ 16 |
quality |
1 |
0. |
controls |
false |
Events
Section titled “Events”With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.
Lottie::readyLottie::errorLottie::playLottie::pauseLottie::end
Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
Press the goal button and a Lottie confetti burst appears, plays once and hides itself: a Lottie entity saved disabled, played by a script when another script emits goal/reached.
Click the amber button to reach the goal. Click again for another burst. Drag to orbit the camera, scroll to zoom.
From a script
Section titled “From a script”Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My Lottie.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My Lottie'); if (!(entity instanceof LottieEntity)) return;
// Its Lottie component holds the settings listed under Props. const component = entity.getComponent(LottieComponent); log('width is', component.props.width); component.setProps({ width: 1.5 });}