Image GIF
Updated
An animated GIF surface.
- Type
ent-image-gif- Script class
GIFEntity- Family
- Media
Overview
Section titled “Overview”An Image GIF entity plays an animated GIF on a plane: a sticker, a looping sign, a small animated decoration. Frames are decoded off the main thread, so the animation does not slow the rest of the world down.
An animation plays only while it can be seen. In play, it runs while its entity is enabled and shown; a hidden entity decodes nothing. In the editor, it plays only while the entity is selected, so a scene full of GIFs costs nothing while you build it. By default a small play/pause pill sits under the plane.
Pick a sibling when it fits better: a Lottie for crisp vector animation that scales well, a Video for long or high-resolution footage with sound, or an Image for a still picture.
The props that matter most, on its GIF component (GIFComponent in scripts):
src: the GIF file, as a URL or an asset from your project.autoplay: start playing once the frames are decoded.repeat:repeatloops;oncestops on the last frame and sendsGIF::end.speed: the playback rate, above 0 and up to 16; 2 plays twice as fast.maxFps: the most frames per second the animation updates, 1 to 60. The scene still renders at full rate.controls: the play/pause and repeat pill under the plane.
It also has the surface props of an Image: width, height, sizing, opacity, color, grayscale, zoom, projection and side. Scripts control playback with play() and pause().
Set it up
Section titled “Set it up”- Add an Image GIF entity to the scene and name it, such as
Sticker. - Set its
srcto an animated GIF, and itswidthandheightin metres, or setsizingtoautoto keep the GIF’s proportions. - Choose
repeat, and turncontrolsoff if visitors should not pause it. - Lower
maxFpsfor decorations that do not need smooth motion. - Add a Signal Emitter to hear its events in scripts, and a Selectable to make it clickable.
Examples
Section titled “Examples”Pause and play on click
Section titled “Pause and play on click”Let the player stop and restart a GIF by clicking it.
#pragma lifecycle(startup)
// Scene: an Image GIF entity "Sticker" with a Selectable and a// Signal Emitter on the signal 'sticker'.let gif;let playing = false;
function startup() { gif = findEntity('Sticker').getComponent(GIFComponent);
on('sticker', (event) => { switch (event.eventType) { case EventType.GIF.Play: playing = true; break; case EventType.GIF.Pause: playing = false; break; case EventType.Selectable.Select: findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again if (playing) gif.pause(); else gif.play(); break; } });}How it works:
GIF::playandGIF::pausereport what really happens, whoever caused it: autoplay, the pill, a script, or the entity being hidden. The script keepsplayingin step with them.- A click (
Selectable::select) callspause()orplay()from that state.
Play once, then hide
Section titled “Play once, then hide”Play a celebration GIF once when a goal is reached, then switch it off.
#pragma lifecycle(startup)
// Scene: an Image GIF entity "Celebrate", saved disabled, with// repeat: once and a Signal Emitter on the signal 'celebrate'.let entity;
function startup() { entity = findEntity('Celebrate');
on('goal/reached', () => { entity.setEnabled(true); entity.getComponent(GIFComponent).play(); });
on('celebrate', (event) => { if (event.eventType === EventType.GIF.End) entity.setEnabled(false); if (event.eventType === EventType.GIF.Error) log('GIF failed:', event.data.message); });}How it works:
- The entity is saved disabled so nothing shows until the goal;
setEnabled(true)brings it in. - With
repeat: 'once',GIF::endarrives at the last frame, and the script switches the entity off again.
Save frames on mobile
Section titled “Save frames on mobile”Use a lower update rate for every GIF in the scene on phones and headsets.
#pragma lifecycle(startup)
#if IS_MOBILE || IS_HEADSETconst FPS = 15;#elseconst FPS = 30;#endif
function startup() { let count = 0; scene.entities.forEach((entity) => { const gif = entity.getComponent(GIFComponent); if (!gif) return; gif.setProps({ maxFps: FPS }); count += 1; }); log('Set maxFps to', FPS, 'on', count, 'GIFs');}How it works:
#if IS_MOBILE || IS_HEADSETpicks the frame rate when the script is compiled: 15 on phones and headsets, 30 elsewhere.scene.entitiesholds every entity of the scene; the script changes only those with a GIF component.maxFpsapplies to the running animation without reloading it.
play()andpause()say what you want; the visibility rule still applies on top, so a hidden GIF stays still afterplay()and starts when shown.- Changing
srcreloads the GIF; the other props apply to the running animation. GIF::readycarriesanimated:falsemeans the file has a single frame, and an Image would do the same job.
Components
Section titled “Components”What a new Image GIF 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. |
| GIF | comp-gif |
Required | One | An animated GIF surface. |
You can also add 18 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 |
controls |
true |
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.
GIF::readyGIF::errorGIF::playGIF::pauseGIF::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.
An animated GIF on an easel that the player pauses and resumes by clicking it; the script follows the GIF’s play and pause events and lowers the frame rate on phones and headsets.
Click the horses to pause them; click again to resume. 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 Image GIF.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My Image GIF'); if (!(entity instanceof GIFEntity)) return;
// Its GIF component holds the settings listed under Props. const component = entity.getComponent(GIFComponent); log('width is', component.props.width); component.setProps({ width: 1.5 });}