Skip to content

Lottie

Updated

A Lottie vector animation surface.

Type
ent-lottie
Script class
LottieEntity
Family
Media

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.
  • autoplay and repeat: start once decoded, and loop (repeat) or stop on the last frame (once, which sends Lottie::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, opacity and color: the plane’s size in metres, its fade and its tint. Lottie does not support sizing.

Scripts control playback with play() and pause().

  1. Add a Lottie entity to the scene and name it, such as Confetti.
  2. Set its src to a Lottie JSON file, and width and height to match the animation’s shape.
  3. Choose repeat; for a one-off effect set once and turn autoplay off so a script starts it.
  4. Keep quality at 1 unless the animation fills much of the view.
  5. Add a Signal Emitter to hear Lottie::end and the other events in scripts.

Start a one-shot animation when a signal arrives.

LottieTrigger.jx
#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; with repeat: 'once' it stops on its last frame.

Show confetti once, then switch the entity off when it ends.

Confetti.jx
#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::end arrives when a once animation reaches its last frame; the script switches the entity off.
  • Lottie::error carries a message when the file cannot load or decode.

Play a spinner faster while waiting, and fade it out when the work is done.

Loader.jx
#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:

  • speed and opacity apply to the running animation without reloading it.
  • Tween.value fades opacity from 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 src or quality reloads the animation; speed, repeat, opacity and 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.

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-transform 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.001 ≤ x ≤ 1000
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.001 ≤ x ≤ 16
controls false

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

  • Lottie::ready
  • Lottie::error
  • Lottie::play
  • Lottie::pause
  • Lottie::end

Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.

Run it in the browser, read its scripts, and download it as an XR Creator project.

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.

LottieEntity.jx
#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 });
}