Skip to content

Notifications

Updated

A notification is a short-lived UI panel the runtime raises in play: a toast that says “Saved” and fades away, a dialog that asks “Delete this?” and waits for an answer, a notice with a progress bar. You show one from a script with NotificationService.show(type, data, options). The runtime builds, places, animates and recycles the panel for you; your script only says what to show, where, and what to do with the answer. A notification shows in front of the viewer, at a corner or edge of the screen, or at a point in the world, and works on a desktop screen, on a phone and in a headset.

A short message that closes by itself is often called a toast; one that waits for an answer is a dialog. Toasts and dialogs are the same thing: a dialog is simply a notification with action buttons that stays until it is answered, and the options alone decide how a notification behaves.

  • Read the UI overview for world space, screen space and the theme.
  • A notification answers on a signal, as UI controls do; see Controls for the event shape and EventType, and Events and signals for how component events arrive on a signal.
  • Notifications show in play only. In the editor, show does nothing.
GlobalWhat it is
NotificationServiceNotifications, passive or asking: show(type, data, { anchor | position, duration, signal }), the answer on signal; update(id, data, options), define(key, build), dismiss(type), has, isOpen.
NotificationTypeThe built-in notifications: Info, Success, Warning, Error, Compact.
Member What it does
show(type, data?, options?) Show a notification: a NotificationType, or a key you defined. Returns nothing; what happens to it arrives on its signal.
update(id, data?, options?) Change the built-in notification on show with that id, in place. Returns false when none is on show, or when it is one of your own design.
dismiss(type) Close every notification of that type on show, each as dismissed.
isOpen(id?) Whether the notification shown with id is on show; without an id, whether any is.
define(key, build) Define a notification of your own design under a new key.
has(key) Whether key is a built-in type or a defined notification.
theme(theme?) Set how the built-in notifications shown from now on look; theme() goes back to the default.

NotificationType names the built-in notifications:

Type Value Icon Colour
NotificationType.Info 'info' Info blue #60a5fa
NotificationType.Success 'success' CircleCheck green #4ade80
NotificationType.Warning 'warning' TriangleAlert amber #fbbf24
NotificationType.Error 'error' CircleX red #f87171
NotificationType.Compact 'compact' none the theme’s primary colour for its bar

A built-in notification shows, from top to bottom: a header with the type’s icon and the bold title, the body text, a row of action buttons, and a progress bar along the bottom edge when it has progress. The colour tints the icon and the bar.

A Compact notification has no header: it shows its text with the actions beside it on one line, as wide as its content up to the theme’s width. It ignores title and icon.

The second argument of show says what the notification shows:

Field What it shows
title The bold heading, exactly as given. Compact ignores it.
text The body text, wrapped at the notification’s width.
icon A Lucide icon name beside the title, in place of the type’s own. Compact ignores it.
actions Buttons, as an array. Pressing one closes the notification and reports its id. See Actions.

An empty title or text creates no text element.

The third argument says where and how it shows:

Option Default What it sets
anchor none Show on screen at 'top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom' or 'bottom-right', stacked with the others there. Head-locked in a headset.
position none Show in the world at { x, y, z }, facing the camera, alone rather than in a stack.
duration 4 Seconds before it closes by itself; Infinity keeps it until it is answered or closed.
dismissable false Whether a press anywhere outside it closes it.
id none Names this showing: showing again with the same id replaces it, and update and isOpen find it.
stackLimit none The most notifications its stack shows at once; one more closes the oldest first.
fade 0.15 Seconds to fade in as it shows and out as it closes; 0 shows and hides it at once.
progress none A bar along its bottom: from 0 to 1, or 'indeterminate' for a sweeping one.
signal none The bus signal its events are emitted on. Without it, nothing reports.
theme none Theme props for this notification alone, laid over the current theme.

With neither anchor nor position, a notification shows in front of the viewer: about 2 m ahead on desktop and 1.2 m in a headset, facing them. It is placed when it shows and then stays put in the world; in XR it travels with the player’s rig. Notifications in front of the viewer, or at the same anchor, form a stack: a column, aligned to the anchor’s side.

  1. Nothing waits. show returns at once. What happens to the notification comes later, on its signal.
  2. It closes by itself after duration seconds. Infinity keeps a dialog until it is answered.
  3. Actions close it. Pressing an action closes the notification and reports the action’s id, unless the action has keepOpen: true.
  4. A press elsewhere closes it only with dismissable: true. Presses in the first moment after it opens are ignored, so the press that raised it cannot close it.
  5. An id replaces. Showing with an id already on show replaces that notification in its place: the old one fades out as the new one fades in, and the old one reports dismiss.
  6. Progress updates in place. update(id, data, options) changes title, text and icon from data and progress from options, without animating the notification again. A new progress value glides to its place. Reaching 1 does not close it; pass progress: undefined to remove the bar.
  7. Leaving the scene closes the notifications on show, as dismissed.

With a signal option, the notification emits these events on it. data.key is its type (or your defined key) and data.id the id it was shown with.

Event EventType Data Sent when
UINotification::open EventType.UINotification.Open { key, id? } It shows.
UINotification::action EventType.UINotification.Action { key, id?, action } An action is pressed; action is its id.
UINotification::dismiss EventType.UINotification.Dismiss { key, id? } It closes without an action: its time ran out, a press outside it, a replacement, dismiss, or a scene change.

Each entry of actions becomes a button:

Field Type Default Description
id string required Reported as action when pressed.
text string the id Button text.
icon string none An icon name beside the label.
variant 'solid', 'subtle', 'bare' 'solid' As on a UI Button. subtle suits a Cancel.
backgroundColor string the theme’s primary colour Fill, for a destructive or secondary choice.
color string the theme’s foreground Label and icon colour.
fontSize number 16 Label size in px.
padding number or number[] 12 Inner padding in px.
disabled boolean false Dim the action and ignore presses.
keepOpen boolean false Report the press but leave the notification open.

NotificationService.theme(theme) sets how the built-in notifications shown from then on look; those already on show keep theirs. Each call sets the whole theme: a prop left out keeps its default, which follows the project’s UI theme. theme() goes back to the defaults. A theme lasts for the play session it was set in. One notification can lay its own props over the current theme with the theme option of show.

Prop What it sets Default
screenScale Size of notifications at an anchor: 1 full size, 0.6 60%. 0.8
width, padding, gap Panel width (the most a Compact one takes), inner spacing, and the space between header, body and actions, in px. 360, 22, 16
backgroundColor, borderColor, borderWidth, borderRadius The panel. the theme’s surface, #2b3648, 1, 18
fontFamily Font of the title, text and buttons: a bundled family or one registered with Fonts. See Placement and fonts. the UI theme’s font
titleFontSize, titleColor, iconSize The header. 18, the theme’s foreground, 22
contentFontSize, contentColor, contentAlign The body. 16, #c7cfdb, 'left'
actionsAlign, actionsGap The action row. 'right', 10
progressColor, progressTrackColor, progressHeight The progress bar. the type’s colour, the theme’s muted colour, 4
types Per built-in type except Compact: its icon and color. A key that is not a built-in type throws. the Types table

A notification’s own icon in its data still wins over its type’s.

NotificationService.define(key, build) registers a design of your own. build(data, answer) runs for each showing and returns any UI element you build: a panel with labels, images, sliders or buttons. show(key, data, options) then shows it, placed like a built-in one.

  1. data is what show was given.
  2. answer(action) closes it and reports action on its signal, as a built-in action does; answer() with nothing closes it as dismissed. Once it has closed, answer does nothing.
  3. Placement, duration, stackLimit, id and fade work as for built-in ones. A press elsewhere never closes a custom notification, and update does not change it.
  4. Wire its buttons once, in startup, not inside build: a listener added for every showing would pile up.
  5. define throws for a key already taken, a built-in type included. A definition lasts for the play session.

A built-in notification is a UI Notification entity (ent-ui-notification): a UI Panel whose UI Notification component (comp-ui-notification) draws the header, body, actions and bar. The service creates, fills and recycles these entities; you do not place them in a scene, and the editor does not offer them. Its props are what show and the theme turn into, such as title, content, icon, actions, actionsInline, dismissable, font and progress. Use show and theme rather than setting them directly.

Welcome.jx
#pragma lifecycle(startup)
function startup() {
NotificationService.show(
NotificationType.Info,
{ title: 'Welcome', text: 'Press E to interact with objects.' },
{ anchor: 'bottom-right', duration: 6, stackLimit: 3 },
);
}

How it works:

  • NotificationType.Info gives the blue info icon. The notification closes by itself after six seconds.
  • anchor: 'bottom-right' pins it to the screen corner, or head-locks it in a headset; stackLimit: 3 keeps at most three toasts in that corner, closing the oldest when a fourth arrives, so the corner does not fill up when other scripts show notifications there too.
  • Give it an action, such as actions: [{ id: 'ok', text: 'Got it' }], and it also closes at once when the player presses it.
ConfirmReset.jx
#pragma lifecycle(startup)
// Scene: a UI Button named 'Reset' with a Signal Emitter on 'ui/ask-reset'.
function resetLevel() {
emit('level/reset');
NotificationService.show(NotificationType.Success, { title: 'Level reset' }, { anchor: 'top' });
}
function startup() {
on('ui:reset', (event) => {
if (event.eventType === EventType.UINotification.Action && event.data.action === 'confirm') resetLevel();
if (event.eventType === EventType.UINotification.Dismiss) log('reset cancelled');
});
on('ui/ask-reset', (event) => {
if (event.eventType !== EventType.UIButton.Press) return;
NotificationService.show(
NotificationType.Warning,
{
title: 'Reset the level?',
text: 'Every object goes back to where it started.',
actions: [
{ id: 'cancel', text: 'Cancel', variant: 'subtle' },
{ id: 'confirm', text: 'Reset', backgroundColor: '#b91c1c' },
],
},
{ anchor: 'center', id: 'reset', duration: Infinity, dismissable: true, signal: 'ui:reset' },
);
});
}

How it works:

  • duration: Infinity keeps the dialog until it is answered. With dismissable: true, a press outside it also closes it, which reports dismiss.
  • The answer arrives on the signal option, ui:reset, as a UINotification::action event whose data.action is the pressed action’s id. Pressing Cancel reports action: 'cancel', so the script only resets on 'confirm'.
  • The id: 'reset' means pressing Reset twice replaces the dialog instead of stacking two.
Download.jx
#pragma lifecycle(startup)
// Scene: nothing to prepare. Simulates a three-second task with a progress bar.
async function startup() {
NotificationService.show(
NotificationType.Info,
{ title: 'Downloading', text: '0%' },
{ id: 'download', anchor: 'bottom-right', duration: Infinity, progress: 0 },
);
await Tween.value(0, 1, (done) => {
NotificationService.update('download', { text: `${Math.round(done * 100)}%` }, { progress: done });
}, { duration: 3 });
NotificationService.update('download', { text: 'Unpacking…' }, { progress: 'indeterminate' });
await new Promise((resolve) => delay(resolve, 1500));
NotificationService.update('download', { title: 'Done', text: 'Ready to play.' }, { progress: undefined });
delay(() => NotificationService.dismiss(NotificationType.Info), 2000);
}

How it works:

  • The id lets update find the notification. Each update changes the text and bar in place, without animating the panel again.
  • progress: 'indeterminate' switches to a sweeping bar for a step of unknown length; progress: undefined removes the bar.
  • Because it was shown with duration: Infinity, the script closes it itself with dismiss, two seconds later.
NotificationTheme.jx
#pragma lifecycle(startup)
// Scene: nothing to prepare. Run this before other scripts show notifications
// (give it a lower execution index).
function startup() {
NotificationService.theme({
screenScale: 0.9,
width: 380,
backgroundColor: '#0f172a',
borderColor: '#334155',
borderRadius: 16,
titleColor: '#f8fafc',
contentColor: '#cbd5e1',
fontFamily: 'nunito',
types: { success: { icon: 'PartyPopper', color: '#22c55e' } },
});
on('quest/complete', (data) => {
NotificationService.show(NotificationType.Success, { title: 'Quest complete', text: data.name }, { anchor: 'top' });
});
on('net/lost', () => {
NotificationService.show(
NotificationType.Error,
{ title: 'Connection lost', text: 'Trying to reconnect…' },
{ anchor: 'top', theme: { backgroundColor: '#7f1d1d' } },
);
});
}

How it works:

  • theme changes every built-in notification shown afterwards: panel colours, corners, font and the Success type’s icon and colour.
  • The theme option of show overrides the panel colour for the error notification only.
ShopOffer.jx
#pragma lifecycle(startup)
// Scene: other scripts emit 'shop/open' to offer an item, and 'coin' when a coin is collected.
let answerShop;
function startup() {
// A floating "+10" that shows where a coin was collected.
NotificationService.define('score', (data) => {
const label = new UILabelEntity();
label.getComponent(UILabelComponent).setProps({ text: `+${data.points}`, fontSize: 32, color: '#facc15' });
return label;
});
// A small shop panel with two buttons.
NotificationService.define('shop', (data, answer) => {
answerShop = answer;
const panel = new UIPanelEntity();
const title = new UILabelEntity();
title.getComponent(UILabelComponent).setProps({ text: `Buy ${data.item}?`, fontSize: 20 });
const buy = new UIButtonEntity();
buy.getComponent(UIButtonComponent).setProps({ text: 'Buy' });
buy.addComponent(new SignalEmitterComponent({ signal: 'shop:buy' }));
const cancel = new UIButtonEntity();
cancel.getComponent(UIButtonComponent).setProps({ text: 'Cancel', variant: 'subtle' });
cancel.addComponent(new SignalEmitterComponent({ signal: 'shop:cancel' }));
panel.add(title, buy, cancel);
return panel;
});
// Wire the buttons once, here, not inside build.
on('shop:buy', () => answerShop?.('buy'));
on('shop:cancel', () => answerShop?.('cancel'));
on('shop:answer', (event) => {
if (event.eventType === EventType.UINotification.Action && event.data.action === 'buy') log('sword bought');
});
on('coin', (data) => {
NotificationService.show('score', { points: 10 }, { position: data.position, duration: 1.5 });
});
on('shop/open', () => {
NotificationService.show('shop', { item: 'Sword' }, { anchor: 'bottom-right', duration: Infinity, signal: 'shop:answer' });
});
}

How it works:

  • define registers two designs. build returns a UI element built with ordinary UI entities; the service places and animates it like a built-in notification.
  • answer('buy') closes the shop panel and reports UINotification::action with action: 'buy' on the signal the panel was shown with, shop:answer.
  • The button listeners are registered once in startup. They call the latest answer, which build stores each time the shop shows.
  • The score notification uses position to stand in the world where the coin was (the emitter sends { position: { x, y, z } }), facing the camera, instead of in a screen stack. A fade option, such as fade: 0.3, makes it appear and disappear more smoothly.
  • A script that may define a design more than once checks NotificationService.has(key) first, because define throws for a key that is already taken.
Trash.jx
#pragma lifecycle(startup)
// Scene: other scripts emit 'item/trashed' with { name } when the player deletes an item.
let lastTrashed = null;
function startup() {
on('ui:trash', (event) => {
if (event.eventType === EventType.UINotification.Action && event.data.action === 'undo' && lastTrashed) {
emit('item/restore', { name: lastTrashed });
lastTrashed = null;
}
});
on('item/trashed', (data) => {
lastTrashed = data.name;
NotificationService.show(
NotificationType.Compact,
{ text: `${data.name} moved to trash`, actions: [{ id: 'undo', text: 'Undo' }] },
{ anchor: 'bottom', id: 'trash', duration: 5, signal: 'ui:trash' },
);
});
}

How it works:

  • A Compact notification shows the text with its Undo button beside it, on one line, at the bottom centre of the screen.
  • Showing again with the same id replaces the previous one, so rapid deletes show only the latest.
  • Another script reports a deletion with emit('item/trashed', { name: 'Crate' }); that on callback receives the data object directly, because it comes from emit.
  • To make an Undo possible, the deleting script only disables the item (setEnabled(false)), and switches it back on when item/restore arrives.

Show an upload’s progress, then a sweeping bar while the server processes it, and finish with a success toast in the same place.

UploadProgress.jx
#pragma lifecycle(startup)
async function startup() {
NotificationService.show(
NotificationType.Info,
{ title: 'Uploading', text: '0%' },
{ id: 'upload', anchor: 'bottom-right', duration: Infinity, progress: 0 },
);
await Tween.value(0, 1, (done) => {
NotificationService.update('upload', { text: `${Math.round(done * 100)}%` }, { progress: done });
}, { duration: 3 });
NotificationService.update('upload', { text: 'Processing…' }, { progress: 'indeterminate' });
await new Promise((resolve) => delay(resolve, 2000));
NotificationService.show(
NotificationType.Success,
{ title: 'Upload complete' },
{ id: 'upload', anchor: 'bottom-right' },
);
}

How it works:

  • The notification is shown once with an id and a starting progress.
  • Tween.value produces numbers from 0 to 1 over three seconds; each one updates the text and the bar without re-animating the panel. A real upload would call update from its own progress reports.
  • progress: 'indeterminate' turns the bar into a sweeping one for a step of unknown length.
  • Showing again with the same id replaces the progress notification with a success toast, which closes after the default four seconds.
  • Waiting for a return value. show returns nothing. Give it a signal and listen for UINotification::action and UINotification::dismiss.
  • No signal, no answer. Without the signal option, nothing reports what the player pressed.
  • A dialog that closes too soon. The default duration is 4 seconds. Use Infinity for anything that needs an answer.
  • Updating without an id. update finds a notification by the id it was shown with; without one, it returns false.
  • Listeners inside build. build runs for every showing; an on inside it adds one more listener each time. Wire buttons in startup.
  • Defining the same key twice. define throws for a key that is taken. Define each design once, in one script.
  • Screen anchors in a headset. An anchored notification is head-locked in XR. Leave out anchor to show it in front of the viewer, carried with the rig.
  • Testing in the editor. Notifications show in play only.