Skip to content

UI Progress

Updated

Progress bar or ring.

Type
ent-ui-progress
Script class
UIProgressEntity
Family
UI

A UI Progress shows how far something has got: a loading bar, a health bar, a download, a cooldown ring. Its UI Progress component (comp-ui-progress) draws either a horizontal bar (type: 'linear', the default) with an optional header label and value, or a ring (type: 'circular') with the value in its centre. When the length of a wait is unknown, indeterminate: true replaces the fill with a moving animation: a segment sweeping along the bar, or a spinning arc.

A progress indicator only displays a value; it takes no pointer and the player cannot change it. It sits nested in a panel or layout, for example in a HUD, a loading screen or a card.

Use a UI Progress to show a value the game controls. For a value the player picks by dragging, use a UI Slider. For a short notice with a bar that appears and goes by itself, a notification with a progress option is simpler; see UI Notification.

The props that matter most:

  • type: 'linear' (a bar) or 'circular' (a ring).
  • value, min and max: the shown value and its range (0 to 100 by default).
  • indeterminate: an animation for a wait of unknown length; value is ignored while it is on.
  • text, showValue and unit: the header label of a bar, whether the value is shown, and a unit after it.
  • color: the fill or arc colour; size: the ring’s diameter in layout pixels (px).
  • direction: 'forward' fills left to right or clockwise from 12 o’clock; 'reverse' the other way.

From a script, setValue(value) and getValue() change and read the value, and setIndeterminate(on) and isIndeterminate() switch the animation. With a Signal Emitter, it reports UIProgress::change { value } when the shown value changes.

  1. Add a UI Progress under a UI Panel or UI Layout. See Scenes and hierarchy.
  2. Choose type, then set min, max and, for a bar, a text label.
  3. Drive it from a script with setValue, or turn on indeterminate while you wait.
  4. Add a Signal Emitter only if another script should hear its change events.

Goal: show the player’s health as a bar that turns red when it runs low.

HealthBar.jx
#pragma lifecycle(startup)
// Scene: a HUD panel with a UI Progress named 'Health'.
// Other scripts emit 'player:damage' and 'player:heal' with an amount.
let health = 100;
function startup() {
const bar = findEntity('Health').getComponent(UIProgressComponent);
bar.setProps({ text: 'Health', min: 0, max: 100, showValue: true });
function refresh() {
bar.setValue(health);
bar.setProps({ color: health <= 25 ? '#ef4444' : '#22c55e' });
}
on('player:damage', (amount) => {
health = Math.max(0, health - amount);
refresh();
});
on('player:heal', (amount) => {
health = Math.min(100, health + amount);
refresh();
});
refresh();
}

How it works:

  • A signal raised with emit('player:damage', 10) passes 10 straight to the callback as amount.
  • setValue(health) moves the fill; the value is kept within min and max.
  • The colour switches to red at a quarter health or less.

Goal: after an ability is used, a ring empties over five seconds and the ability is ready again.

Cooldown.jx
#pragma lifecycle(startup, update)
// Scene: a UI Progress named 'Dash Cooldown' in a HUD.
// Other scripts emit 'ability:dash' when the player dashes.
const COOLDOWN = 5; // seconds
let left = 0;
let ring;
function startup() {
ring = findEntity('Dash Cooldown').getComponent(UIProgressComponent);
ring.setProps({ type: 'circular', size: 56, min: 0, max: COOLDOWN, showValue: false, direction: 'reverse' });
ring.setValue(0);
on('ability:dash', () => {
if (left > 0) return;
left = COOLDOWN;
});
}
function update(dt) {
if (left <= 0) return;
left = Math.max(0, left - dt);
ring.setValue(left);
if (left === 0) emit('ability:ready', { ability: 'dash' });
}

How it works:

  • type: 'circular' draws a ring 56 px across; showValue: false keeps its centre empty.
  • The range is the cooldown itself, 0 to 5 seconds, so setValue(left) shows the time left directly.
  • direction: 'reverse' runs the arc counter-clockwise, so the ring visibly unwinds as time passes.
  • update(dt) counts down by the seconds since the last frame and announces when the ability is ready.

Goal: show an indeterminate bar while a scene loads, then a full bar.

LoadNext.jx
#pragma lifecycle(startup)
// Scene: a UI Progress named 'Loading', a UI Label named 'Status',
// and a UI Button named 'Go' with a Signal Emitter on 'travel:go'.
// A scene with the id 'harbour' exists in the project.
function startup() {
const bar = findEntity('Loading').getComponent(UIProgressComponent);
const status = findEntity('Status').getComponent(UILabelComponent);
bar.setProps({ text: 'Harbour', unit: '%' });
bar.setValue(0);
on('travel:go', async (event) => {
if (event.eventType !== EventType.UIButton.Press) return;
status.setProps({ text: 'Loading…' });
bar.setIndeterminate(true);
await Scenes.load('harbour', { additive: true });
bar.setIndeterminate(false);
bar.setValue(100);
status.setProps({ text: 'Ready' });
});
}

How it works:

  • setIndeterminate(true) starts the sweeping animation, since the script cannot know how far the load has got.
  • The listener is async, so it can await Scenes.load(…); additive: true adds the new scene beside the current one, so this panel stays.
  • Once loading finishes, the animation stops and setValue(100) fills the bar.

What a new UI Progress 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.
UI Progress comp-ui-progress Required One Progress bar or ring.

You can also add 3 optional components, such as Networkable, Networkable Trait, Signal Emitter.

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
type "linear"
min 0 -1000000000 ≤ x ≤ 1000000000
max 100 -1000000000 ≤ x ≤ 1000000000
showValue true
indeterminate false
direction "forward"

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

  • UIProgress::change

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 UI Progress.

UIProgressEntity.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My UI Progress');
if (!(entity instanceof UIProgressEntity)) return;
// Its UI Progress component holds the settings listed under Props.
const component = entity.getComponent(UIProgressComponent);
log('min is', component.props.min);
component.setProps({ min: 1 });
}