Skip to content

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.

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.

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:

  1. Script to UI. Find the entity, get its component, and call setProps({ … }) or a method such as setText, setValue or setChecked. The element rebuilds only what changed.
  2. UI to script. Give the control’s entity a Signal Emitter with a signal, then listen with on(signal, (event) => …) and compare event.eventType against an EventType constant. event.data carries the details, such as { value } for a slider.

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.

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

  2. Under it, add two UI Label entities named Title and Count, and a UI Button named Press. Set the title’s text to World-space UI, the count’s to Pressed 0 times, and the button’s to Press me. The panel’s layout stacks them in a column.

  3. Add a Signal Emitter to the Press button and set its signal to counter/press. Without it, the button sends no events.

  4. 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'}` });
    });
    }
  5. Enter play and press the button. The label counts each press.

How it works:

  • #pragma lifecycle(startup) tells the engine to call startup once when the script starts.
  • findEntity('Count') finds the label by name, once, and getComponent(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 on event.eventType ignores any other event that might share the signal.
  • setProps({ text }) changes the label; the layout resizes around the new text by itself.
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 NotificationService Notifications
A label floating over an object, or a custom font UI Label with Billboard, Fonts Placement and fonts

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:

EntityTypeWhat it is
UI Avatarent-ui-avatarRound profile picture with a status dot.
UI Buttonent-ui-buttonA button with a label or an icon; each press sends an event.
UI Checkboxent-ui-checkboxA checkbox with a label.
UI Dividerent-ui-dividerA thin separator line.
UI Drawingent-ui-drawingA canvas scripts can draw on: paint, minimaps, charts.
UI Imageent-ui-imageAn image element.
UI Inputent-ui-inputSingle-line text field.
UI Keyboardent-ui-keyboardAn on-screen letter keyboard.
UI Labelent-ui-labelA text label.
UI Layoutent-ui-layoutFlexbox container that arranges child UI elements.
UI Listent-ui-listScrolling list of selectable rows.
UI List Itement-ui-list-itemOne row of a UI List.
UI Menuent-ui-menuOpens a popup menu when clicked.
UI Menu Itement-ui-menu-itemOne entry of a UI Menu.
UI Notificationent-ui-notificationNotification card with icon, title, text and buttons.
UI Panelent-ui-panelBackground box of an element: fill, rounded corners, border.
UI Progressent-ui-progressProgress bar or ring.
UI Render Sceneent-ui-render-sceneThe small 3D world a UI Render View shows.
UI Render Viewent-ui-render-viewShows a small 3D scene inside the UI.
UI Sliderent-ui-sliderDrag to pick a value.
UI Spacerent-ui-spacerInvisible flexible gap that pushes siblings apart.
UI Switchent-ui-switchAn on/off switch.
UI Toggle Buttonent-ui-toggle-buttonA button that stays on until clicked again.
UI Videoent-ui-videoA video element.

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

GlobalWhat it is
UIPanelEntityA 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.
UILayoutEntityA 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
SignalEmitterComponentOpt-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.
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.
FontsThe app's font families: await Fonts.register(family, url, { weight, label }) for this session, unregister, has(family), families.
EventTypeEvery event type a script can hear, by who sends it: compare them rather than typing the strings.
onCall callback(data) right away each time signal is emitted; returns a function that stops it. Released with the script.
ComponentTypeWhat it does
UI Avatarcomp-ui-avatarRound profile picture with a status dot.
UI Backdropcomp-ui-backdropSolid back so a panel is not see-through from behind.
UI Buttoncomp-ui-buttonA button with a label or an icon; each press sends an event.
UI Checkboxcomp-ui-checkboxA checkbox with a label.
UI Dividercomp-ui-dividerA thin separator line.
UI Drawingcomp-ui-drawingA canvas scripts can draw on: paint, minimaps, charts.
UI Handlecomp-ui-handleDrag grip on a panel's edge for moving it.
UI Imagecomp-ui-imageAn image element.
UI Inputcomp-ui-inputSingle-line text field.
UI Keyboard Numericcomp-ui-keyboard-numericOn-screen number keypad.
UI Keyboard Qwertycomp-ui-keyboard-qwertyAn on-screen letter keyboard.
UI Labelcomp-ui-labelA text label.
UI Layoutcomp-ui-layoutFlexbox container that arranges child UI elements.
UI Listcomp-ui-listScrolling list of selectable rows.
UI List Itemcomp-ui-list-itemOne row of a UI List.
UI Menucomp-ui-menuOpens a popup menu when clicked.
UI Menu Itemcomp-ui-menu-itemOne entry of a UI Menu.
UI Notificationcomp-ui-notificationNotification card with icon, title, text and buttons.
UI Panelcomp-ui-panelBackground box of an element: fill, rounded corners, border.
UI Progresscomp-ui-progressProgress bar or ring.
UI Render Scenecomp-ui-render-sceneThe small 3D world a UI Render View shows.
UI Render Viewcomp-ui-render-viewShows a small 3D scene inside the UI.
UI Screen Spacecomp-ui-screen-spacePins a panel to the screen as a HUD.
UI Selection Groupcomp-ui-selection-groupMakes toggles exclusive, like radio buttons.
UI Slidercomp-ui-sliderDrag to pick a value.
UI Spacercomp-ui-spacerInvisible flexible gap that pushes siblings apart.
UI Switchcomp-ui-switchAn on/off switch.
UI Toggle Buttoncomp-ui-toggle-buttonA button that stays on until clicked again.
UI Tooltipcomp-ui-tooltipHover tooltip for any UI element.
UI Videocomp-ui-videoA video element.
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 NotificationService, their answers, themes and custom designs.
Placement and fonts Where an element ends up, labels pinned to objects, font families and Fonts.