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.
Before you start
Section titled “Before you start”- 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,
showdoes nothing.
| Global | What it is |
|---|---|
NotificationService | Notifications, 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. |
NotificationType | The built-in notifications: Info, Success, Warning, Error, Compact. |
NotificationService
Section titled “NotificationService”| Member | What it does |
|---|---|
show(type, data?, options?) |
Show a notification: a Notification, 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 |
|---|---|---|---|
Notification |
'info' |
Info |
blue #60a5fa |
Notification |
'success' |
CircleCheck |
green #4ade80 |
Notification |
'warning' |
TriangleAlert |
amber #fbbf24 |
Notification |
'error' |
CircleX |
red #f87171 |
Notification |
'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.
Options
Section titled “Options”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-, 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.
How notifications behave
Section titled “How notifications behave”- Nothing waits.
showreturns at once. What happens to the notification comes later, on itssignal. - It closes by itself after
durationseconds.Infinitykeeps a dialog until it is answered. - Actions close it. Pressing an action closes the notification and reports the action’s
id, unless the action haskeepOpen: true. - 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. - An
idreplaces. Showing with anidalready on show replaces that notification in its place: the old one fades out as the new one fades in, and the old one reportsdismiss. - Progress updates in place.
update(id, data, options)changestitle,textandiconfromdataandprogressfromoptions, without animating the notification again. A new progress value glides to its place. Reaching1does not close it; passprogress: undefinedto remove the bar. - Leaving the scene closes the notifications on show, as dismissed.
Events
Section titled “Events”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 |
Event |
{ key, id? } |
It shows. |
UINotification::action |
Event |
{ key, id?, action } |
An action is pressed; action is its id. |
UINotification::dismiss |
Event |
{ key, id? } |
It closes without an action: its time ran out, a press outside it, a replacement, dismiss, or a scene change. |
Actions
Section titled “Actions”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. |
background |
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 |
background, 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 |
content, contentColor, contentAlign |
The body. | 16, #c7cfdb, 'left' |
actionsAlign, actionsGap |
The action row. | 'right', 10 |
progressColor, progress, progress |
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.
Custom notifications
Section titled “Custom notifications”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.
datais whatshowwas given.answer(action)closes it and reportsactionon itssignal, as a built-in action does;answer()with nothing closes it as dismissed. Once it has closed,answerdoes nothing.- Placement,
duration,stackLimit,idandfadework as for built-in ones. A press elsewhere never closes a custom notification, andupdatedoes not change it. - Wire its buttons once, in
startup, not insidebuild: a listener added for every showing would pile up. definethrows for a key already taken, a built-in type included. A definition lasts for the play session.
The UI Notification component
Section titled “The UI Notification component”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.
Reset asks first: a Warning notification with Cancel and Reset actions reports the answer on its signal, and the script reads the UI Notification component of the dialog it opened. A tip above the crates is a UI Notification entity pinned in the world.
Press Scatter crates, then Reset level: a dialog asks first. Press Reset to send the crates home, or Cancel or a press outside it to keep them. Drag outside the panels to orbit the camera.
Examples
Section titled “Examples”1. A welcome toast
Section titled “1. A welcome toast”#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 }, );}A welcome toast that slides in at the bottom right when play starts and closes by itself after six seconds: NotificationService.show from a Behavior script, with nothing to prepare in the scene.
Watch the bottom-right corner of the view. Reload the example to see it again.
How it works:
NotificationType.Infogives 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: 3keeps 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.
2. A confirmation dialog
Section titled “2. A confirmation dialog”#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' }, ); });}Reset opens a warning notification with Cancel and Reset actions in the middle of the screen; confirming shows a success notification.
Press Reset, then choose Reset or Cancel in the dialog.
How it works:
duration: Infinitykeeps the dialog until it is answered. Withdismissable: true, a press outside it also closes it, which reportsdismiss.- The answer arrives on the
signaloption,ui:reset, as aUINotification::actionevent whosedata.actionis the pressed action’sid. Pressing Cancel reportsaction: 'cancel', so the script only resets on'confirm'. - The
id: 'reset'means pressing Reset twice replaces the dialog instead of stacking two.
3. Progress updated in place
Section titled “3. Progress updated in place”#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);}One notification with an id is updated in place: a progress bar fills over three seconds, turns indeterminate while unpacking, then reports done.
Watch the notification in the bottom-right corner fill, unpack and finish. Reload the example to see it again.
How it works:
- The
idletsupdatefind 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: undefinedremoves the bar.- Because it was shown with
duration: Infinity, the script closes it itself withdismiss, two seconds later.
4. A themed set of notifications
Section titled “4. A themed set of notifications”#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' } }, ); });}A script themes every notification once, with colours, a font and a party icon for successes; a connection error overrides the theme for itself.
Press Lose connection to show a themed error notification.
How it works:
themechanges every built-in notification shown afterwards: panel colours, corners, font and the Success type’s icon and colour.- The
themeoption ofshowoverrides the panel colour for the error notification only.
5. A notification of your own design
Section titled “5. A notification of your own design”#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' }); });}A script defines a shop notification built from UI entities, with Buy and Cancel buttons that answer it.
Press Open shop, then Buy or Cancel in the panel that appears.
How it works:
defineregisters two designs.buildreturns 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 reportsUINotification::actionwithaction: 'buy'on thesignalthe panel was shown with,shop:answer.- The button listeners are registered once in
startup. They call the latestanswer, whichbuildstores each time the shop shows. - The score notification uses
positionto stand in the world where the coin was (the emitter sends{ position: { x, y, z } }), facing the camera, instead of in a screen stack. Afadeoption, such asfade: 0.3, makes it appear and disappear more smoothly. - A script that may define a design more than once checks
NotificationService.has(key)first, becausedefinethrows for a key that is already taken.
Snippets
Section titled “Snippets”1. One-line undo
Section titled “1. One-line undo”#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
Compactnotification shows the text with its Undo button beside it, on one line, at the bottom centre of the screen. - Showing again with the same
idreplaces the previous one, so rapid deletes show only the latest. - Another script reports a deletion with
emit('item/trashed', { name: 'Crate' }); thatoncallback receives the data object directly, because it comes fromemit. - To make an Undo possible, the deleting script only disables the item (
setEnabled(false)), and switches it back on whenitem/restorearrives.
2. Progress, then a success toast
Section titled “2. Progress, then a success toast”Show an upload’s progress, then a sweeping bar while the server processes it, and finish with a success toast in the same place.
#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' }, );}A notification shown once and updated in place: a progress bar driven by Tween.value, a sweeping bar, then a success toast with the same id.
Watch the notification at the bottom right of the view.
How it works:
- The notification is shown once with an
idand a startingprogress. Tween.valueproduces 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 callupdatefrom its own progress reports.progress: 'indeterminate'turns the bar into a sweeping one for a step of unknown length.- Showing again with the same
idreplaces the progress notification with a success toast, which closes after the default four seconds.
Common mistakes
Section titled “Common mistakes”- Waiting for a return value.
showreturns nothing. Give it asignaland listen forUINotification::actionandUINotification::dismiss. - No
signal, no answer. Without thesignaloption, nothing reports what the player pressed. - A dialog that closes too soon. The default
durationis 4 seconds. UseInfinityfor anything that needs an answer. - Updating without an
id.updatefinds a notification by theidit was shown with; without one, it returnsfalse. - Listeners inside
build.buildruns for every showing; anoninside it adds one more listener each time. Wire buttons instartup. - Defining the same key twice.
definethrows 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
anchorto show it in front of the viewer, carried with the rig. - Testing in the editor. Notifications show in play only.