UI
Updated
The UI is MIRA’s one system for everything a player reads or presses: menus, heads-up displays (HUDs), inventories, dialogs, labels pinned to objects, in-world screens and an in-scene keyboard. Every piece of UI is an ordinary entity in the scene hierarchy, so you build it in the editor like any other object and drive it from Behavior scripts. The same panel works on desktop, on mobile and in a VR or AR headset, and its text stays sharp at any distance.
A world-space UI: a UI Panel root laid out as a column, two UI Labels and a UI Button whose press a script counts.
Press the button. Drag to orbit the camera, scroll to zoom.
Key concepts
Section titled “Key concepts”UI entity and UI component. Each UI element is an entity whose type starts with ent-ui- (for example ent-ui-button) and carries a component whose type starts with comp-ui- (for example comp-ui-button). The entity is the thing in the hierarchy; the component holds the props you style and the methods you call. In a script you reach the component with entity.getComponent(UIButtonComponent).
Root and nested elements. A UI is a tree in the scene hierarchy. The topmost UI element, usually a UI Panel, is the root: it is placed in the world (or on the screen) and drawn. Every UI element directly below it, or below a nested panel or layout, is nested: its parent’s layout places it in hierarchy order. A nested element’s Transform has no effect, so you move it with layout props, not with its position. Only the direct parent counts, so a UI element under a plain Group becomes a root of its own.
Layout. Panels and layouts arrange their children in a row or a column, like a CSS flexbox: flexDirection, alignItems, justifyContent, gap and padding decide where each child goes. Children follow their order in the hierarchy.
Layout pixels. Sizes, padding and font sizes are in layout pixels (px). In world space one layout pixel is pixelSize metres, 0.003 m by default, so a 300 px wide panel is 0.9 m wide. On screen, one layout pixel is one screen pixel.
World space and screen space. A root UI lives either in the world, at its entity’s transform (the default), or pinned to a corner, edge or the centre of the screen, drawn over the scene, when it carries a UI Screen Space component.
Theme. Every UI component falls back to the project’s theme for colours, sizes, spacing and font. A prop you set always wins over the theme. The theme is set for the whole project; scripts cannot change it, but they can restyle any element by setting its props.
Events through a Signal Emitter. A control reports what happened (a press, a new slider value, typed text) only while its entity has a Signal Emitter. The emitter puts each event on the event bus under its signal, and a script listens with on(signal, callback). Each event has an eventType such as EventType.UIButton.Press, and its details in event.data. In the other direction, a script finds the entity, gets its component with getComponent, and calls setProps({ … }) or a method such as setText, setValue or setChecked.
How it works
Section titled “How it works”A UI tree is built from three kinds of elements:
- Containers arrange their children. A UI Layout is a bare flexbox container; a UI Panel is a layout with a visible surface (fill, rounded corners, border); a UI List is a scrolling layout of selectable rows. See Panels and layout.
- Controls are what a player presses, drags or types into: buttons, checkboxes, switches, toggle buttons, sliders, progress bars, text inputs, lists, menus and tooltips. See Controls.
- Content shows things: text labels, images, round avatars, video, a canvas scripts draw on, and a small 3D world inside a panel. See Content.
UI Panel "Settings" root: placed by its transform (or by UI Screen Space)├── UI Label "Settings"├── UI Layout a row: flexDirection 'row'│ ├── UI Switch "Music"│ └── UI Spacer└── UI Slider "Volume"Where an element sits in the hierarchy decides how it is placed. Under a UI Layout or UI Panel it is laid out inside it. Under a 3D object or at the scene root it becomes a root of its own. See Placement and fonts.
UI reacts in play and is inert while you edit: in the editor a click selects the element instead of pressing it. In play, mouse, touch and XR controller or hand rays all press UI the same way. Hover effects and tooltips need a pointer that can hover, which a touch screen does not have.
A script talks to UI in two directions:
- Script to UI. Find the entity, get its component, and call
setProps({ … })or a method such assetText,setValueorsetChecked. The element rebuilds only what changed. - UI to script. Give the control’s entity a Signal Emitter with a
signal, then listen withon(signal, (event) => …)and compareevent.eventTypeagainst anEventTypeconstant.event.datacarries the details, such as{ value }for a slider.
Your first UI
Section titled “Your first UI”This walkthrough builds a world-space panel with a title, a counter label and a button, then counts presses from a script. It is the same scene as the UI panel example.
-
Add a UI Panel entity to the scene and name it
Counter. Place it about 1.5 m above the floor, in front of the spawn point. It is the root of the UI. -
Under it, add two UI Label entities named
TitleandCount, and a UI Button namedPress. Set the title’stexttoWorld-space UI, the count’s toPressed 0 times, and the button’s toPress me. The panel’s layout stacks them in a column. -
Add a Signal Emitter to the
Pressbutton and set itssignaltocounter/press. Without it, the button sends no events. -
Add a Behavior entity and give it this script:
Counter.jx #pragma lifecycle(startup)// Scene: a UI Panel with a UI Label named 'Count' and a UI Button// whose Signal Emitter uses the signal 'counter/press'.let presses = 0;function startup() {const count = findEntity('Count').getComponent(UILabelComponent);on('counter/press', (event) => {if (event.eventType !== EventType.UIButton.Press) return;presses += 1;count.setProps({ text: `Pressed ${presses} ${presses === 1 ? 'time' : 'times'}` });});} -
Enter play and press the button. The label counts each press.
How it works:
#pragma lifecycle(startup)tells the engine to callstartuponce when the script starts.findEntity('Count')finds the label by name, once, andgetComponent(UILabelComponent)returns its label component.on('counter/press', …)runs the callback every time the button’s Signal Emitter puts an event on that signal. The check onevent.eventTypeignores any other event that might share the signal.setProps({ text })changes the label; the layout resizes around the new text by itself.
Choosing
Section titled “Choosing”| If you want … | Use … | Read |
|---|---|---|
| A card, menu or dialog with a visible background | UI Panel | Panels and layout |
| A panel that stands in the world, a kiosk or a sign | A UI Panel root at its entity’s transform | Panels and layout |
| A HUD pinned to a corner of the screen | A UI Panel with UI Screen Space | Panels and layout |
| An invisible row or column to group and align elements | UI Layout | Panels and layout |
| A thin line between sections | UI Divider | Panels and layout |
| Flexible space that pushes elements apart | UI Spacer | Panels and layout |
| An action that runs once per press | UI Button | Controls |
| A lit button that stays on, such as a tool or a microphone | UI Toggle Button | Controls |
| An option to tick, or radio buttons | UI Checkbox, with a UI Selection Group for radio buttons | Controls |
| A setting that switches on or off at once | UI Switch | Controls |
| A number picked by dragging | UI Slider | Controls |
| A progress bar or ring, or a waiting animation | UI Progress | Controls |
| A text field | UI Input | Controls |
| A keyboard fixed in the scene, such as on a kiosk | UI Keyboard | Controls |
| A scrolling list of selectable rows | UI List and UI List Item | Controls |
| A button that opens a popup of choices | UI Menu and UI Menu Item | Controls |
| Text: a title, a score, a caption, a tag over an object | UI Label | Content |
| A picture | UI Image | Content |
| A round profile picture with a status dot | UI Avatar | Content |
| A video or live stream in a panel | UI Video | Content |
| A canvas scripts draw on: charts, minimaps, paint | UI Drawing | Content |
| A live 3D model turning inside a panel | UI Render View with a UI Render Scene | Content |
| A toast, a confirmation dialog, a progress notice shown from a script | UI Notification, through Notification |
Notifications |
| A label floating over an object, or a custom font | UI Label with Billboard, Fonts |
Placement and fonts |
Entity types
Section titled “Entity types”Each UI element is an entity type whose name starts with ent-ui-. Each has a page of its components, props, events and a first script:
| Entity | Type | What it is |
|---|---|---|
| UI Avatar | ent-ui-avatar | Round profile picture with a status dot. |
| UI Button | ent-ui-button | A button with a label or an icon; each press sends an event. |
| UI Checkbox | ent-ui-checkbox | A checkbox with a label. |
| UI Divider | ent-ui-divider | A thin separator line. |
| UI Drawing | ent-ui-drawing | A canvas scripts can draw on: paint, minimaps, charts. |
| UI Image | ent-ui-image | An image element. |
| UI Input | ent-ui-input | Single-line text field. |
| UI Keyboard | ent-ui-keyboard | An on-screen letter keyboard. |
| UI Label | ent-ui-label | A text label. |
| UI Layout | ent-ui-layout | Flexbox container that arranges child UI elements. |
| UI List | ent-ui-list | Scrolling list of selectable rows. |
| UI List Item | ent-ui-list-item | One row of a UI List. |
| UI Menu | ent-ui-menu | Opens a popup menu when clicked. |
| UI Menu Item | ent-ui-menu-item | One entry of a UI Menu. |
| UI Notification | ent-ui-notification | Notification card with icon, title, text and buttons. |
| UI Panel | ent-ui-panel | Background box of an element: fill, rounded corners, border. |
| UI Progress | ent-ui-progress | Progress bar or ring. |
| UI Render Scene | ent-ui-render-scene | The small 3D world a UI Render View shows. |
| UI Render View | ent-ui-render-view | Shows a small 3D scene inside the UI. |
| UI Slider | ent-ui-slider | Drag to pick a value. |
| UI Spacer | ent-ui-spacer | Invisible flexible gap that pushes siblings apart. |
| UI Switch | ent-ui-switch | An on/off switch. |
| UI Toggle Button | ent-ui-toggle-button | A button that stays on until clicked again. |
| UI Video | ent-ui-video | A video element. |
In scripts
Section titled “In scripts”These globals are the ones UI scripts use most. Every UI entity and component class is a global too, so you can create UI from code with new UIPanelEntity() and find components with getComponent(UISliderComponent).
| Global | What it is |
|---|---|
UIPanelEntity | A visible surface that arranges its children: a UILayoutEntity plus the UIPanelComponent fill, radius and border. The panel is also what carries the chrome a bare layout has no business with — backdrop, tooltip and drag handle. |
UILayoutEntity | A flex container for arranging child UI entities — arrangement and nothing else: no fill, no border, no backdrop. Use UIPanelEntity when the container is a visible surface. |
UILabelEntity | |
UIButtonEntity | |
UILabelComponent | |
UIButtonComponent | |
SignalEmitterComponent | Opt-in marker: when present, sibling components (input, audio, physics, …) send their events to it, each as a ComponentEvent: { entityId, eventType, data }, and it emits the ones its eventFilter allows on the event bus under its signal. An entity may carry several, each with its own signal and eventFilter: every event goes to all of them, so Selectable::select and Selectable::deselect can go out on different signals. |
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. |
Fonts | The app's font families: await Fonts.register(family, url, { weight, label }) for this session, unregister, has(family), families. |
EventType | Every event type a script can hear, by who sends it: compare them rather than typing the strings. |
on | Call callback(data) right away each time signal is emitted; returns a function that stops it. Released with the script. |
Components
Section titled “Components”| Component | Type | What it does |
|---|---|---|
| UI Avatar | comp-ui-avatar | Round profile picture with a status dot. |
| UI Backdrop | comp-ui-backdrop | Solid back so a panel is not see-through from behind. |
| UI Button | comp-ui-button | A button with a label or an icon; each press sends an event. |
| UI Checkbox | comp-ui-checkbox | A checkbox with a label. |
| UI Divider | comp-ui-divider | A thin separator line. |
| UI Drawing | comp-ui-drawing | A canvas scripts can draw on: paint, minimaps, charts. |
| UI Handle | comp-ui-handle | Drag grip on a panel's edge for moving it. |
| UI Image | comp-ui-image | An image element. |
| UI Input | comp-ui-input | Single-line text field. |
| UI Keyboard Numeric | comp-ui-keyboard-numeric | On-screen number keypad. |
| UI Keyboard Qwerty | comp-ui-keyboard-qwerty | An on-screen letter keyboard. |
| UI Label | comp-ui-label | A text label. |
| UI Layout | comp-ui-layout | Flexbox container that arranges child UI elements. |
| UI List | comp-ui-list | Scrolling list of selectable rows. |
| UI List Item | comp-ui-list-item | One row of a UI List. |
| UI Menu | comp-ui-menu | Opens a popup menu when clicked. |
| UI Menu Item | comp-ui-menu-item | One entry of a UI Menu. |
| UI Notification | comp-ui-notification | Notification card with icon, title, text and buttons. |
| UI Panel | comp-ui-panel | Background box of an element: fill, rounded corners, border. |
| UI Progress | comp-ui-progress | Progress bar or ring. |
| UI Render Scene | comp-ui-render-scene | The small 3D world a UI Render View shows. |
| UI Render View | comp-ui-render-view | Shows a small 3D scene inside the UI. |
| UI Screen Space | comp-ui-screen-space | Pins a panel to the screen as a HUD. |
| UI Selection Group | comp-ui-selection-group | Makes toggles exclusive, like radio buttons. |
| UI Slider | comp-ui-slider | Drag to pick a value. |
| UI Spacer | comp-ui-spacer | Invisible flexible gap that pushes siblings apart. |
| UI Switch | comp-ui-switch | An on/off switch. |
| UI Toggle Button | comp-ui-toggle-button | A button that stays on until clicked again. |
| UI Tooltip | comp-ui-tooltip | Hover tooltip for any UI element. |
| UI Video | comp-ui-video | A video element. |
In this section
Section titled “In this section”| Topic | Description |
|---|---|
| Panels and layout | Layouts, panels, screen-space HUDs, backdrops, dividers, spacers, selection groups and drag handles. |
| Controls | Buttons, toggles, sliders, progress, text input, keyboards, lists, menus and tooltips, with their events. |
| Content | Labels, images, avatars, video, drawing canvases and 3D render views. |
| Notifications | Toasts and dialogs from Notification, their answers, themes and custom designs. |
| Placement and fonts | Where an element ends up, labels pinned to objects, font families and Fonts. |