Skip to content

UI List Item

Updated

One row of a UI List.

Type
ent-ui-list-item
Script class
UIListItemEntity
Family
UI

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:

  • text and value: the row’s label, and the identifier it reports.
  • selected: whether the row starts selected.
  • icon and badge: an icon name beside the label, and a count in a badge.
  • selectedColor and backgroundColor: 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.

  1. Add UI List Item entities directly under a UI List, in the order they should appear. See Scenes and hierarchy.
  2. Set each row’s text, and a value if the name is not a good identifier.
  3. Listen on the list’s Signal Emitter for selections, or give a row its own emitter when it should act by itself.

Goal: a list of destinations where pressing a row teleports at once, with no selection.

Teleports.jx
#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::select with its value, here the entity’s name.

Goal: rows built from data, each with a badge for unread messages that clears when the row is opened.

Inbox.jx
#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 text and a stable value, the thread id.
  • badge shows the unread count; 0 hides it, so opening a thread clears its badge.
  • The list’s emitter reports the selected row’s value, used to find the row in the Map.

Goal: select the row the player picked last time when the list appears.

RestorePick.jx
#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’s value getter gives its identifier.
  • setChecked(true) selects the row, and in single mode the list deselects the others.

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-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
UI List Item comp-ui-list-item 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

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.

Run it in the browser, read its scripts, and download it as an XR Creator project.

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.

UIListItemEntity.jx
#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);
}