UI Layout
Updated
Flexbox container that arranges child UI elements.
- Type
ent-ui-layout- Script class
UILayoutEntity- Family
- UI
Overview
Section titled “Overview”A UI Layout is an invisible container: it arranges its children in a column or a row and draws nothing itself. It carries only a UI Layout component (comp-ui-layout), the same flexbox container a UI Panel uses, without the panel’s surface. “Flexbox” means the children flow one after another along a main direction, and a few props decide how they spread along it and line up across it.
Most layouts are nested inside a panel to build its structure: a row of buttons at the bottom of a dialog, two columns side by side, a header with a title on the left and a close button on the right. A layout can also be a root of its own, in world space at its transform or in screen space with a UI Screen Space component, when the elements should float without any background, such as a row of icon buttons over the scene.
Use a UI Layout to group or align elements with no visible box. Use a UI Panel when the group needs a fill, rounded corners or a border, and a UI List for a scrolling column of selectable rows.
The props that matter most:
flexDirection:'column'(the default) stacks children top to bottom;'row'places them left to right.justifyContent: how children spread along the flow:'flex-start'(the default),'center','flex-end'or'space-between'.alignItems: how children line up across the flow:'stretch'(the default) makes them as wide as a column or as tall as a row;'center','flex-start'and'flex-end'keep their own size.gapandpadding: the space between children and the space inside the edges, in layout pixels (px).width,heightandflexGrow: a fixed size in px or a percentage such as'50%', or a share of the parent’s free space.positionType: 'absolute'withpositionTop,positionRight,positionBottomandpositionLeft: take a nested layout out of the flow and pin it against its parent’s edges, for overlays and badges.
Set it up
Section titled “Set it up”- Add a UI Layout directly under the panel or layout it belongs to. See Scenes and hierarchy.
- Set
flexDirection, thenjustifyContent,alignItemsandgap. - Add its elements directly under it, in order. Their transforms are ignored; the layout places them.
- For a free-floating group, place the layout at the scene root or under a 3D object instead. It is then a root, 300 px wide by default, placed by its transform, or by a UI Screen Space component for a HUD.
Examples
Section titled “Examples”A dialog’s button row
Section titled “A dialog’s button row”Goal: add a row of two buttons, aligned to the right, at the bottom of an existing panel.
#pragma lifecycle(startup)
// Scene: a UI Panel named 'Dialog' (a column). The script adds the button row at its bottom.function startup() { const dialog = findEntity('Dialog');
const row = new UILayoutEntity(); row.getComponent(UILayoutComponent).setProps({ flexDirection: 'row', justifyContent: 'flex-end', gap: 8 });
const cancel = new UIButtonEntity(); cancel.getComponent(UIButtonComponent).setProps({ text: 'Cancel', variant: 'subtle' }); cancel.addComponent(new SignalEmitterComponent({ signal: 'dialog/cancel' }));
const ok = new UIButtonEntity(); ok.getComponent(UIButtonComponent).setProps({ text: 'OK' }); ok.addComponent(new SignalEmitterComponent({ signal: 'dialog/ok' }));
row.add(cancel, ok); dialog.add(row);
on('dialog/ok', (event) => { if (event.eventType === EventType.UIButton.Press) dialog.setEnabled(false); }); on('dialog/cancel', (event) => { if (event.eventType === EventType.UIButton.Press) dialog.setEnabled(false); });}How it works:
flexDirection: 'row'places the buttons side by side, andjustifyContent: 'flex-end'pushes them to the right end of the row.- The row stretches to the panel’s width because the panel’s
alignItemsis'stretch'by default. - Added last with
dialog.add(row), the row comes after the panel’s other children, at the bottom of the column. - Each button has its own Signal Emitter, so each press arrives on its own signal.
Switch between a row and a column
Section titled “Switch between a row and a column”Goal: let the player flip a group of cards between a wide row and a narrow column.
#pragma lifecycle(startup)
// Scene: a UI Panel holding a UI Layout named 'Cards' (with a few elements inside)// and a UI Button named 'Flip' whose Signal Emitter uses 'cards/flip'.let wide = true;
function startup() { const cards = findEntity('Cards').getComponent(UILayoutComponent); const flip = findEntity('Flip').getComponent(UIButtonComponent);
function apply() { cards.setProps({ flexDirection: wide ? 'row' : 'column', gap: wide ? 16 : 8 }); flip.setText(wide ? 'Show as column' : 'Show as row'); }
on('cards/flip', (event) => { if (event.eventType !== EventType.UIButton.Press) return; wide = !wide; apply(); });
apply();}How it works:
- Changing
flexDirectionre-flows the layout’s children at once; the parent panel resizes around the new shape. gapchanges with it, so the row gets more breathing room than the column.- The button label always describes what the next press does.
A badge over a picture
Section titled “A badge over a picture”Goal: pin a small “NEW” tag to the top-right corner of an image, without pushing anything else aside.
#pragma lifecycle(startup)
// Scene: a UI Panel named 'Item Card' holding a UI Image.function startup() { const card = findEntity('Item Card');
const badge = new UILayoutEntity(); badge.getComponent(UILayoutComponent).setProps({ positionType: 'absolute', positionTop: 8, positionRight: 8, foreground: true, });
const tag = new UILabelEntity(); tag.getComponent(UILabelComponent).setProps({ text: 'NEW', fontSize: 12, fontWeight: 'bold', padding: [2, 8], backgroundColor: '#dc2626', borderRadius: 8, });
badge.add(tag); card.add(badge);}How it works:
positionType: 'absolute'takes the layout out of the card’s flow: it takes no room, and the image keeps its place.positionTopandpositionRightplace it 8 px in from the card’s top and right edges.foreground: truedraws it above images in the normal flow, so the picture never covers the tag.
Components
Section titled “Components”What a new UI Layout 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. |
You can also add 5 optional components, such as Follow Target, Networkable, Networkable Trait, Signal Emitter, UI Screen Space.
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({ … }).
| Prop | Default | Range |
|---|---|---|
renderMode |
"overlay" |
|
alignItems |
"stretch" |
|
justify |
"flex-start" |
|
flexDirection |
"column" |
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 profile card built from a UI Avatar with initials and a status dot, a UI Spacer that pushes the level badge right, and UI Dividers between the stats. Pressing the avatar cycles the status.
Press the avatar to cycle Online, Away and Busy: the status dot and the label change together. Drag outside the panel to orbit the camera, scroll to zoom.
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 Layout.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My UI Layout'); if (!(entity instanceof UILayoutEntity)) return;
// Its UI Layout component holds the settings listed under Props. const component = entity.getComponent(UILayoutComponent); log(component.props);}