UI List Item
Updated
One row of a UI List.
- Type
ent-ui-list-item- Script class
UIListItemEntity- Family
- UI
Overview
Section titled “Overview”A UI List Item is one row of a UI List. Its UI List Item component (comp-ui-list-item) draws a left-aligned, subtle button with a label, an optional icon and badge, and a selected state that fills the row with selectedColor. A new row shows the text Item.
A row belongs to the nearest UI List above it, so place it nested under a list. The list decides how pressing works: in 'single' mode a press selects the row and deselects the others, in 'multiple' it flips the row, and in 'none' rows are plain actions.
Each row has a value, the identifier reported when it is picked; it defaults to the entity’s name. With a Signal Emitter on the row, it reports UIListItem::select { value } on every press, whatever the list’s mode. To hear every row at once, put one emitter on the list instead and listen for UIList::select.
The props that matter most:
textandvalue: the row’s label, and the identifier it reports.selected: whether the row starts selected.iconandbadge: an icon name beside the label, and a count in a badge.selectedColorandbackgroundColor: the fill while selected, and a resting fill (transparent by default).disabled: dims the row and ignores presses.
From a script, the component’s isChecked() and setChecked(selected) read and change the selected state, and its value getter returns the value.
Set it up
Section titled “Set it up”- Add UI List Item entities directly under a UI List, in the order they should appear. See Scenes and hierarchy.
- Set each row’s
text, and avalueif the name is not a good identifier. - Listen on the list’s Signal Emitter for selections, or give a row its own emitter when it should act by itself.
Examples
Section titled “Examples”Rows that act directly
Section titled “Rows that act directly”Goal: a list of destinations where pressing a row teleports at once, with no selection.
#pragma lifecycle(startup)
// Scene: a UI List named 'Places' with selection 'none', whose UI List Item rows// are named 'Lobby', 'Garden' and 'Roof' and each have a Signal Emitter on 'places:go'.function startup() { on('places:go', (event) => { if (event.eventType !== EventType.UIListItem.Select) return; emit('travel/to', { place: event.data.value }); });}How it works:
- With
selection: 'none', rows show no selected state and behave as buttons. - Each row’s own Signal Emitter reports
UIListItem::selectwith itsvalue, here the entity’s name.
An inbox with unread counts
Section titled “An inbox with unread counts”Goal: rows built from data, each with a badge for unread messages that clears when the row is opened.
#pragma lifecycle(startup)
// Scene: a UI List named 'Inbox' (selection 'single', Signal Emitter: 'inbox').const THREADS = [ { id: 'crew', title: 'Crew chat', unread: 4 }, { id: 'market', title: 'Market', unread: 0 }, { id: 'quests', title: 'Quest board', unread: 2 },];
function startup() { const inbox = findEntity('Inbox'); const rows = new Map();
for (const thread of THREADS) { const row = new UIListItemEntity(); const item = row.getComponent(UIListItemComponent); item.setProps({ text: thread.title, value: thread.id, badge: thread.unread }); rows.set(thread.id, item); inbox.add(row); }
on('inbox', (event) => { if (event.eventType !== EventType.UIList.Select) return; rows.get(event.data.value)?.setProps({ badge: 0 }); emit('inbox/open', { thread: event.data.value }); });}How it works:
- Each row gets a readable
textand a stablevalue, the thread id. badgeshows the unread count;0hides it, so opening a thread clears its badge.- The list’s emitter reports the selected row’s
value, used to find the row in theMap.
Restore a saved selection
Section titled “Restore a saved selection”Goal: select the row the player picked last time when the list appears.
#pragma lifecycle(startup)
// Scene: a UI List named 'Characters' (selection 'single') with rows whose values are// 'scout', 'builder' and 'medic'. Another script emits 'profile:loaded' with { character }.function startup() { const list = findEntity('Characters').getComponent(UIListComponent);
on('profile:loaded', (profile) => { for (const row of list.getItems()) { if (row.value === profile.character) row.setChecked(true); } });}How it works:
getItems()returns the list’s rows; each row’svaluegetter gives its identifier.setChecked(true)selects the row, and insinglemode the list deselects the others.
Components
Section titled “Components”What a new UI List Item 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 List Item | comp- |
Required | One | One row of a UI List. |
You can also add 4 optional components, such as Link, Signal Emitter, UI Selection Group, UI Tooltip.
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 |
|---|---|---|
text |
"Item" |
|
iconPosition |
"left" |
|
align |
"left" |
|
selected |
false |
|
disabled |
false |
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.
UIListItem::select
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 Item.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My UI List Item'); if (!(entity instanceof UIListItemEntity)) return;
// Its UI List Item component holds the settings listed under Props. const component = entity.getComponent(UIListItemComponent); log(component.props);}