Skip to content

UI Input

Updated

Single-line text field.

Type
ent-ui-input
Script class
UIInputEntity
Family
UI

A UI Input is a text field the player types into: a name, a chat message, a search term, a door code. Its UI Input component (comp-ui-input) draws the field with an optional header label above it and grey placeholder text while it is empty, and keeps the typed text itself. A press on the field gives it focus, and a press outside takes focus away.

Which keyboard types into it depends on the device:

  • On desktop and mobile, the physical keyboard or the device’s on-screen keyboard. With virtualKeyboard: true, the in-scene UI Keyboard appears inside the view instead, for example on a touch kiosk.
  • In a headset, the headset’s system keyboard when it has one; otherwise the in-scene keyboard appears just below the field’s panel.

The field sits nested in a panel or layout. With a Signal Emitter on its entity, it reports UIInput::change on every edit, UIInput::submit when the player presses Enter, and UIInput::focus and UIInput::blur when it gains and loses focus, each with { text }.

Use a UI Input for free text. For a number picked within a range, a UI Slider is quicker, especially in XR. For a choice from fixed options, use a UI List or UI Menu.

The props that matter most:

  • value: the current text (empty by default).
  • text and placeholder: the header label above the field, and the hint shown while it is empty.
  • type: 'text' (the default), 'password' (masked) or 'number' (asks for the numeric keyboard).
  • maxLength and maxRows: the most characters accepted, and the lines visible before the text scrolls (above 1, the field is multiline).
  • clearable: a clear button while the field has text.
  • virtualKeyboard: show the in-scene keyboard on desktop and mobile too.

From a script, getValue() reads the text and setValue(text) replaces it (cut to maxLength, and sending change); the component’s isFocused getter says whether the field has focus.

  1. Add a UI Input under a UI Panel or UI Layout. See Scenes and hierarchy.
  2. Set text (the label), placeholder and maxLength; pick a type.
  3. Add a Signal Emitter with a signal, so it reports edits and Enter.
  4. In a Behavior, handle EventType.UIInput.Submit for the final text, and EventType.UIInput.Change if you need it as it is typed.

Goal: greet the player once they type their name and press Enter.

AskName.jx
#pragma lifecycle(startup)
// Scene: a UI Input named 'Name' (Signal Emitter: 'profile:name') and a UI Label named 'Greeting'.
function startup() {
const field = findEntity('Name').getComponent(UIInputComponent);
const greeting = findEntity('Greeting').getComponent(UILabelComponent);
field.setProps({ text: 'Your name', placeholder: 'Type, then press Enter', maxLength: 20, clearable: true });
on('profile:name', (event) => {
if (event.eventType !== EventType.UIInput.Submit) return;
const name = event.data.text.trim();
if (!name) return;
greeting.setProps({ text: `Welcome, ${name}!` });
emit('profile/named', { name });
});
}

How it works:

  • maxLength: 20 caps the name; clearable: true adds a button that empties the field.
  • UIInput::submit arrives when the player presses Enter, or the enter key of the in-scene keyboard, with the whole text in event.data.text.
  • The script trims spaces, ignores an empty name, and tells other scripts with emit.

Goal: a numeric field with the in-scene keyboard; the right code opens the door, a wrong one shows a warning.

DoorCode.jx
#pragma lifecycle(startup)
// Scene: a kiosk panel with a UI Input named 'Code' (Signal Emitter: 'door:code').
const SECRET = '4071';
function startup() {
const code = findEntity('Code').getComponent(UIInputComponent);
code.setProps({ text: 'Door code', type: 'password', maxLength: 4, virtualKeyboard: true });
on('door:code', (event) => {
if (event.eventType !== EventType.UIInput.Submit) return;
if (event.data.text === SECRET) {
NotificationService.show(NotificationType.Success, { title: 'Door unlocked' }, { anchor: 'top' });
emit('door/open');
} else {
NotificationService.show(NotificationType.Warning, { title: 'Wrong code', text: 'Try again.' }, { anchor: 'top' });
}
code.setValue('');
});
}

How it works:

  • type: 'password' masks the digits on screen; getValue() and the events still carry the real text in play.
  • virtualKeyboard: true shows the in-scene keyboard on a touch screen or desktop as well; in a headset it opens on its own.
  • NotificationService.show raises a short toast at the top of the screen for each answer.
  • setValue('') empties the field for the next try.

Goal: hide the rows of a list that do not match the search text.

Search.jx
#pragma lifecycle(startup)
// Scene: a UI Input named 'Search' (Signal Emitter: 'catalog:search')
// above a UI List named 'Catalog' whose UI List Item rows have readable texts.
function startup() {
const search = findEntity('Search').getComponent(UIInputComponent);
const list = findEntity('Catalog').getComponent(UIListComponent);
search.setProps({ placeholder: 'Search…', clearable: true });
on('catalog:search', (event) => {
if (event.eventType !== EventType.UIInput.Change) return;
const query = event.data.text.trim().toLowerCase();
for (const row of list.getItems()) {
const text = (row.props.text ?? '').toLowerCase();
row.entity.setEnabled(text.includes(query));
}
});
}

How it works:

  • UIInput::change arrives on every keystroke with the whole text, so the list follows as the player types.
  • getItems() returns the list’s rows as UI List Item components; row.entity is each row’s entity.
  • setEnabled(false) takes a row out of the list until it matches again. An empty search matches every row.

What a new UI Input 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 Input comp-ui-input Required One Single-line text field.

You can also add 2 optional components, such as Signal Emitter, 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
value ""
type "text"
clearable false
disabled false
virtualKeyboard false

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

  • UIInput::change
  • UIInput::submit
  • UIInput::focus
  • UIInput::blur

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 Input.

UIInputEntity.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My UI Input');
if (!(entity instanceof UIInputEntity)) return;
// Its UI Input component holds the settings listed under Props.
const component = entity.getComponent(UIInputComponent);
log(component.props);
}