UI List
Updated
Scrolling list of selectable rows.
- Type
ent-ui-list- Script class
UIListEntity- Family
- UI
Overview
Section titled “Overview”A UI List is a scrolling column of rows the player picks from: levels, songs, saved games, teleport destinations. It is a UI Layout (comp-ui-layout) with no gap or padding, plus a UI List component (comp-ui-list) that makes the UI List Item entities below it selectable rows and scrolls them when they overflow. Touch and controller drags can scroll it even when they start on a row; a tap still presses the row.
A list sits nested in a panel, or stands as a root of its own. It draws no fill; add a UI Panel component to it for one.
Selection follows selection:
'single'(the default): pressing a row selects it and deselects the rest.'multiple': each press flips its row.'none': rows are plain actions with no selected state.
With a Signal Emitter on the list entity, it reports UIList::select and UIList::deselect with { value } for every row, so one emitter covers them all. Each row’s value is its entity’s name unless you set it.
Use a UI List for many choices, especially more than fit on screen. For a few choices behind a button, use a UI Menu. For one choice among two to four always visible, radio checkboxes work well.
The props that matter most:
selection:'single','multiple'or'none'.heightormaxHeighton its UI Layout: without one, the list grows to fit every row and never scrolls.scrollbar,scrollbarWidthandscrollbarColor: the scrollbar shown while the content overflows.
From a script, the component’s selectedValues() returns the selected rows’ values and getItems() the rows; the UI List entity also has selectedValues(), scrollTo(x, y) and the scrollPosition getter.
Set it up
Section titled “Set it up”- Add a UI List under a UI Panel. See Scenes and hierarchy.
- Set
selection, and aheightormaxHeighton its UI Layout so it scrolls. - Add UI List Item entities under it, one per row; set each row’s
textandvalue. - Add one Signal Emitter to the list entity and listen for
EventType.UIList.Select.
Examples
Section titled “Examples”Pick a level, then play
Section titled “Pick a level, then play”Goal: choose one level from a list and start it with a Play button.
#pragma lifecycle(startup)
// Scene: a UI List named 'Levels' (selection 'single', Signal Emitter: 'levels')// whose rows have the values 'forest', 'cave' and 'castle' (scene ids),// and a UI Button named 'Play' (Signal Emitter: 'levels:play').function startup() { const list = findEntity('Levels').getComponent(UIListComponent); const play = findEntity('Play').getComponent(UIButtonComponent); play.setDisabled(true);
on('levels', (event) => { if (event.eventType !== EventType.UIList.Select) return; play.setText(`Play ${event.data.value}`); play.setDisabled(false); });
on('levels:play', async (event) => { if (event.eventType !== EventType.UIButton.Press) return; const [level] = list.selectedValues(); if (level) await Scenes.load(level); });}How it works:
- One Signal Emitter on the list reports every row, because
UIList::selectcomes from the list. - Play stays disabled until a row is selected.
selectedValues()returns the selected values; insinglemode there is at most one, used here as a scene id forScenes.load.
A basket with several choices
Section titled “A basket with several choices”Goal: tick several items and keep a running total.
#pragma lifecycle(startup)
// Scene: a UI List named 'Market' (selection 'multiple', Signal Emitter: 'market')// whose rows have the values 'apple', 'bread' and 'cheese', and a UI Label named 'Total'.const PRICES = { apple: 1, bread: 3, cheese: 5 };
function startup() { const list = findEntity('Market').getComponent(UIListComponent); const total = findEntity('Total').getComponent(UILabelComponent);
function refresh() { const picked = list.selectedValues(); const sum = picked.reduce((acc, value) => acc + (PRICES[value] ?? 0), 0); total.setProps({ text: `${picked.length} items · ${sum} coins` }); }
on('market', (event) => { if (event.eventType === EventType.UIList.Select || event.eventType === EventType.UIList.Deselect) refresh(); });
refresh();}How it works:
- In
multiplemode each press flips a row, sendingselectordeselect. refreshreads the whole selection each time instead of tracking it by hand.
Rows from data, scrolled to the top
Section titled “Rows from data, scrolled to the top”Goal: build the rows from an array and jump back to the top with a button.
#pragma lifecycle(startup)
// Scene: a UI List named 'Songs' and a UI Button named 'Top' (Signal Emitter: 'songs:top').const SONGS = ['Harbour Lights', 'Northern Road', 'Paper Moon', 'Glass River', 'Late Train', 'Copper Sky', 'Low Tide', 'Open Field'];
function startup() { const songs = findEntity('Songs'); songs.getComponent(UILayoutComponent).setProps({ maxHeight: 200 });
for (const title of SONGS) { const row = new UIListItemEntity(); row.getComponent(UIListItemComponent).setProps({ text: title, value: title }); songs.add(row); }
on('songs:top', (event) => { if (event.eventType === EventType.UIButton.Press) songs.scrollTo(0, 0); });}How it works:
maxHeight: 200on the list’s layout caps its height, so the eight rows scroll.- Each
new UIListItemEntity()becomes a row of the list it is added under. scrollTo(0, 0)on the UI List entity scrolls back to the top; offsets are in layout pixels.
Components
Section titled “Components”What a new UI List 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 List | comp-ui-list |
Required | One | Scrolling list of selectable rows. |
You can also add 7 optional components, such as Follow Target, Networkable, Networkable Trait, Signal Emitter, UI Panel, 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({ … }).
UI Layout
Section titled “UI Layout”| Prop | Default | Range |
|---|---|---|
renderMode |
"overlay" |
|
alignItems |
"stretch" |
|
justify |
"flex-start" |
|
flexDirection |
"column" |
UI List
Section titled “UI List”| Prop | Default | Range |
|---|---|---|
selection |
"single" |
|
scrollbar |
true |
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.
UIList::selectUIList::deselect
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.
A UI List of levels with icons and a locked row: selecting a row enables the Play button, and Play loads the scene whose id is the row's value.
Pick a level in the list, then press Play to load its scene. Frozen Peak is disabled. Run the example again to choose another level. 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 List.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My UI List'); if (!(entity instanceof UIListEntity)) return;
// Its UI Layout component holds the settings listed under Props. const component = entity.getComponent(UILayoutComponent); log(component.props);}