Skip to content

UI Notification

Updated

Notification card with icon, title, text and buttons.

Type
ent-ui-notification
Script class
None
Family
UI

A UI Notification is the panel behind every built-in toast and dialog: a “Saved” message that fades away, a “Delete this?” question that waits for an answer, a notice with a progress bar. It is a UI Panel (a UI Layout and a UI Panel component) with a UI Notification component (comp-ui-notification) that draws, from top to bottom, a header with an icon and a bold title, the body text, a row of action buttons, and an optional progress bar along the bottom edge.

You never place one. The editor does not offer it, and it has no script class: a script asks NotificationService to show a notification, and the runtime creates, fills, places, animates and recycles these entities itself. Notifications show in play only.

Where it appears depends on the options of show:

  • In front of the viewer (no anchor or position): about 2 m ahead on desktop and 1.2 m in a headset, then it stays put in the world; in XR it travels with the player’s rig.
  • On screen, with anchor such as 'top' or 'bottom-right', stacked with others at that anchor.
  • In the world at a position, facing the camera.

The type, NotificationType.Info, Success, Warning, Error or Compact, sets the icon and colour; Compact is a single line of text with its actions beside it.

What matters most when you show one:

  • title, text and actions in the data: what it says and which buttons it offers.
  • duration: seconds before it closes by itself, 4 by default; Infinity keeps a dialog until it is answered.
  • signal: the signal its events arrive on. Without it, nothing reports what the player pressed.
  • id: names the showing, so showing again replaces it and update can change it in place.
  • progress: a bar from 0 to 1, or 'indeterminate'.

With a signal, it reports UINotification::open, UINotification::action (with the pressed action’s id in data.action) and UINotification::dismiss when it closes without an action. Set the look of every notification with NotificationService.theme(…) rather than the component’s props.

  1. Nothing to place in the scene.
  2. In a Behavior, call NotificationService.show(type, data, options) with a NotificationType, what to show, and where.
  3. For a dialog, add actions, duration: Infinity and a signal, and listen on that signal for EventType.UINotification.Action.

Goal: a short success message at the top of the screen.

CheckpointToast.jx
#pragma lifecycle(startup)
// Scene: other scripts emit 'checkpoint/reached' with { name }.
function startup() {
on('checkpoint/reached', (data) => {
NotificationService.show(
NotificationType.Success,
{ title: 'Checkpoint', text: data.name },
{ anchor: 'top', duration: 3, stackLimit: 2 },
);
});
}

How it works:

  • NotificationType.Success gives the green check icon; it closes by itself after three seconds.
  • stackLimit: 2 keeps at most two toasts at the top, closing the oldest first.

Goal: ask before leaving the room, and act only on Leave.

ConfirmLeave.jx
#pragma lifecycle(startup)
// Scene: a UI Button named 'Leave' with a Signal Emitter on 'room:ask-leave'.
function startup() {
on('room:leave-answer', (event) => {
if (event.eventType === EventType.UINotification.Action && event.data.action === 'leave') {
emit('room/leave');
}
});
on('room:ask-leave', (event) => {
if (event.eventType !== EventType.UIButton.Press) return;
NotificationService.show(
NotificationType.Warning,
{
title: 'Leave the room?',
text: 'Your unsaved changes will be lost.',
actions: [
{ id: 'stay', text: 'Stay', variant: 'subtle' },
{ id: 'leave', text: 'Leave', backgroundColor: '#b91c1c' },
],
},
{ id: 'leave-dialog', duration: Infinity, dismissable: true, signal: 'room:leave-answer' },
);
});
}

How it works:

  • With no anchor, the dialog shows in front of the viewer, which also suits a headset.
  • duration: Infinity keeps it until answered; dismissable: true lets a press outside close it, reported as dismiss.
  • Pressing an action closes it and reports its id on the signal. Only 'leave' acts.
  • id: 'leave-dialog' means pressing Leave twice replaces the dialog instead of stacking two.

Goal: show an upload’s progress and finish with a message.

UploadProgress.jx
#pragma lifecycle(startup)
// Scene: other scripts emit 'upload/progress' with a fraction from 0 to 1, then 'upload/done'.
function startup() {
on('upload/progress', (fraction) => {
if (!NotificationService.isOpen('upload')) {
NotificationService.show(
NotificationType.Info,
{ title: 'Uploading', text: '0%' },
{ id: 'upload', anchor: 'bottom-right', duration: Infinity, progress: 0 },
);
}
NotificationService.update('upload', { text: `${Math.round(fraction * 100)}%` }, { progress: fraction });
});
on('upload/done', () => {
NotificationService.update('upload', { title: 'Uploaded', text: 'All done.' }, { progress: undefined });
delay(() => NotificationService.dismiss(NotificationType.Info), 2000);
});
}

How it works:

  • isOpen('upload') checks whether the notification with that id is on show, so it is shown only once.
  • update changes the text and the bar in place, without animating the panel again.
  • progress: undefined removes the bar; since it was shown with duration: Infinity, the script closes it with dismiss two seconds later.

What a new UI Notification 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 Layout comp-ui-layout Required One Flexbox container that arranges child UI elements.
UI Panel comp-ui-panel Required One Background box of an element: fill, rounded corners, border.
UI Notification comp-ui-notification Required One Notification card with icon, title, text and buttons.
Signal Emitter comp-signal-emitter Starts with Several Collects events from sibling components and sends them on as signals.

You can also add 13 optional components, such as Billboard, Enable On Signal, Grabbable, Handle, Networkable, Networkable Trait.

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
renderMode "overlay"
alignItems "stretch"
justifyContent "flex-start"
flexDirection "column"
Prop Default Range
borderRadius 18
borderColor "#2b3648"
borderWidth 1
opacity 1 0 ≤ x ≤ 1
Prop Default Range
contentAlign "left"
actionsAlign "right"
dismissable false
actions []
Prop Default Range
signal "ui:notification"

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

  • UINotification::open
  • UINotification::action
  • UINotification::dismiss

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 Notification.

Script.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My UI Notification');
// Its UI Layout component holds the settings listed under Props.
const component = entity.getComponent(UILayoutComponent);
log(component.props);
}