UI Notification
Updated
Notification card with icon, title, text and buttons.
- Type
ent-ui-notification- Script class
- None
- Family
- UI
Overview
Section titled “Overview”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
anchororposition): 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
anchorsuch 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,textandactionsin the data: what it says and which buttons it offers.duration: seconds before it closes by itself, 4 by default;Infinitykeeps 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 andupdatecan change it in place.progress: a bar from0to1, 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.
Set it up
Section titled “Set it up”- Nothing to place in the scene.
- In a Behavior, call
NotificationService.show(type, data, options)with aNotificationType, what to show, and where. - For a dialog, add
actions,duration: Infinityand asignal, and listen on that signal forEventType.UINotification.Action.
Examples
Section titled “Examples”A toast when a checkpoint is reached
Section titled “A toast when a checkpoint is reached”Goal: a short success message at the top of the screen.
#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.Successgives the green check icon; it closes by itself after three seconds.stackLimit: 2keeps at most two toasts at the top, closing the oldest first.
A confirmation dialog
Section titled “A confirmation dialog”Goal: ask before leaving the room, and act only on Leave.
#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: Infinitykeeps it until answered;dismissable: truelets a press outside close it, reported asdismiss.- Pressing an action closes it and reports its
idon thesignal. Only'leave'acts. id: 'leave-dialog'means pressing Leave twice replaces the dialog instead of stacking two.
Progress updated in place
Section titled “Progress updated in place”Goal: show an upload’s progress and finish with a message.
#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 thatidis on show, so it is shown only once.updatechanges the text and the bar in place, without animating the panel again.progress: undefinedremoves the bar; since it was shown withduration: Infinity, the script closes it withdismisstwo seconds later.
Components
Section titled “Components”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- |
Required | One | Position, rotation and scale of the entity, with optional editor-only per-axis locks. |
| UI Layout | comp- |
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- |
Required | One | Notification card with icon, title, text and buttons. |
| Signal Emitter | comp- |
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({ … }).
UI Layout
Section titled “UI Layout”| Prop | Default | Range |
|---|---|---|
renderMode |
"overlay" |
|
alignItems |
"stretch" |
|
justify |
"flex-start" |
|
flexDirection |
"column" |
UI Panel
Section titled “UI Panel”| Prop | Default | Range |
|---|---|---|
borderRadius |
18 |
|
borderColor |
"#2b3648" |
|
borderWidth |
1 |
|
opacity |
1 |
0 ≤ x ≤ 1 |
UI Notification
Section titled “UI Notification”| Prop | Default | Range |
|---|---|---|
contentAlign |
"left" |
|
actionsAlign |
"right" |
|
dismissable |
false |
|
actions |
[] |
Signal Emitter
Section titled “Signal Emitter”| Prop | Default | Range |
|---|---|---|
signal |
"ui:notification" |
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.
UINotification::openUINotification::actionUINotification::dismiss
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.
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.
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 UI Notification.
#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);}