UI Panel
Updated
Background box of an element: fill, rounded corners, border.
- Type
ent-ui-panel- Script class
UIPanelEntity- Family
- UI
Overview
Section titled “Overview”A UI Panel is the card that holds a user interface: a menu, a HUD, a dialog, a kiosk screen. It is two components on one entity. Its UI Layout (comp-ui-layout) is a flexbox container that arranges the panel’s children in a column or a row, and its UI Panel component (comp-ui-panel) paints the surface behind them: a fill, rounded corners and an optional border. Everything you put under the panel moves, hides and shows with it.
A panel is usually the root of a UI, the topmost UI element in its branch of the hierarchy:
- In world space (the default), it stands in the scene at its entity’s transform, like a sign. One layout pixel is
pixelSizemetres, 0.003 m by default, so the default root width of 300 px is 0.9 m. Players can see it from any angle and press it with a mouse, a finger or an XR controller ray. - In screen space, with a UI Screen Space component, it is pinned to a corner, an edge or the centre of the screen and drawn over the scene, for a HUD on desktop and mobile.
- Nested in another panel or a UI Layout, it becomes a card inside that UI, laid out by its parent like any other element.
Use a UI Panel whenever the UI needs a visible background. Use a UI Layout for an invisible group, such as a row of buttons inside a panel, and a UI List for a scrolling column of selectable rows.
The props that matter most:
flexDirection,gapandpaddingon the UI Layout: whether children stack in a'column'(the default) or a'row', the space between them and the space inside the panel’s edge, in layout pixels (px).widthon the UI Layout: a fixed width in px; without it, a root is 300 px wide and as tall as its content.backgroundColor,borderRadiusandopacityon the UI Panel: the fill, the corner radius in px, and the fill’s alpha (0draws no fill, for an invisible grouping panel).renderModeandstackOrderon the UI Layout of a root: whether walls can hide the panel ('world') or it draws over the scene ('overlay', the default), and which of two overlapping panels draws in front.
A panel also takes the extras a floating card needs: a UI Backdrop for a solid back, a Grabbable and a UI Handle to let players drag it, a Billboard to face the camera, Enable on Signal to show or hide it on a signal, and Don’t Unload to keep it across scene switches.
Set it up
Section titled “Set it up”- Add a UI Panel at the scene root, or under the 3D object it belongs to. Either way it becomes a root. For a world-space panel, place it about 1.5 m above the floor, facing where players stand. See Scenes and hierarchy.
- On its UI Layout, choose
flexDirection,gap,paddingand, if needed, awidth. - On its UI Panel, set
backgroundColor,borderRadiusand, optionally,borderColorfor an outline. - Add the elements directly under the panel, in the order they should appear: labels, buttons, sliders, nested layouts. Their own transforms are ignored; the panel’s layout places them.
- For a HUD, add a UI Screen Space component and pick an
anchor. For a world panel players can walk around, add a UI Backdrop.
Examples
Section titled “Examples”A welcome card built from code
Section titled “A welcome card built from code”Goal: create a world-space panel with a title, a divider and a hint when the scene starts, with nothing prepared in the editor.
#pragma lifecycle(startup)
// Scene: nothing to prepare. The card appears 1.6 m up, 2 m in front of the origin.function startup() { const card = new UIPanelEntity(); card.getComponent(UILayoutComponent).setProps({ width: 360, padding: 20, gap: 10, alignItems: 'center' }); card.getComponent(UIPanelComponent).setProps({ backgroundColor: '#0f172a', borderColor: '#6366f1', borderRadius: 16 });
const title = new UILabelEntity(); title.getComponent(UILabelComponent).setProps({ text: 'Welcome aboard', fontSize: 28, fontWeight: 'bold' });
const line = new UIDividerEntity();
const hint = new UILabelEntity(); hint.getComponent(UILabelComponent).setProps({ text: 'Walk to the glowing door to begin.', color: '#a5b4fc' });
card.add(title, line, hint); card.position.set(0, 1.6, -2); scene.add(card);}How it works:
new UIPanelEntity()creates a panel that already carries a UI Layout and a UI Panel;getComponentreaches each one to set its props.alignItems: 'center'centres the children across the column.padding: 20keeps them 20 px from every edge, andgap: 10spaces them.card.add(...)nests the title, the divider and the hint in that order. Nested, their transforms are ignored and the column places them.scene.add(card)puts the root in the scene, and its position decides where it stands.
Open and close a menu panel
Section titled “Open and close a menu panel”Goal: a small always-visible button shows and hides a larger menu panel.
#pragma lifecycle(startup)
// Scene:// - a UI Panel named 'Menu' (the menu itself),// - a separate UI Panel named 'Menu Button Bar' holding a UI Button named 'Menu Button'// whose Signal Emitter uses the signal 'hud/menu'.let open = false;
function startup() { const menu = findEntity('Menu'); const button = findEntity('Menu Button').getComponent(UIButtonComponent);
function apply() { menu.setEnabled(open); button.setText(open ? 'Close menu' : 'Menu'); }
on('hud/menu', (event) => { if (event.eventType !== EventType.UIButton.Press) return; open = !open; apply(); });
apply();}How it works:
setEnabled(false)on the panel entity hides it and every element under it;setEnabled(true)brings them all back.- The button lives in its own panel. If it were inside the menu, it would disappear with the menu and could not reopen it.
applysets both the panel and the button label from one variable,open, so they never disagree.
A status card that changes colour
Section titled “A status card that changes colour”Goal: a panel’s fill and border follow the player’s health, which other scripts report on a signal.
#pragma lifecycle(startup)
// Scene: a UI Panel named 'Status' holding a UI Label named 'Health Text'.// Other scripts call emit('player:health', value) with a value from 0 to 100.function startup() { const surface = findEntity('Status').getComponent(UIPanelComponent); const text = findEntity('Health Text').getComponent(UILabelComponent);
on('player:health', (health) => { text.setProps({ text: `Health ${health}` }); if (health < 25) { surface.setProps({ backgroundColor: '#450a0a', borderColor: '#f87171', borderWidth: 3 }); } else { surface.setProps({ backgroundColor: '#0f172a', borderColor: '#334155', borderWidth: 1 }); } });}How it works:
- A signal raised with
emit(signal, data)passesdatastraight to theoncallback, sohealthis the number another script sent. setPropson the UI Panel component changes only the surface; the label and the layout are untouched.- The border is drawn because
borderColoris set;borderWidthsets its thickness in px.
Components
Section titled “Components”What a new UI Panel 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. |
You can also add 19 optional components, such as Animation Graph, Animation Timeline, Billboard, Dont Unload, Enable On Signal, Follow Target.
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 |
|---|---|---|
opacity |
1 |
0 ≤ x ≤ 1 |
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.
It reports the events every entity has: 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.
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.
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 Panel.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My UI Panel'); if (!(entity instanceof UIPanelEntity)) return;
// Its UI Layout component holds the settings listed under Props. const component = entity.getComponent(UILayoutComponent); log(component.props);}