UI Input
Updated
Single-line text field.
- Type
ent-ui-input- Script class
UIInputEntity- Family
- UI
Overview
Section titled “Overview”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).textandplaceholder: 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).maxLengthandmaxRows: 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.
Set it up
Section titled “Set it up”- Add a UI Input under a UI Panel or UI Layout. See Scenes and hierarchy.
- Set
text(the label),placeholderandmaxLength; pick atype. - Add a Signal Emitter with a
signal, so it reports edits and Enter. - In a Behavior, handle
EventType.UIInput.Submitfor the final text, andEventType.UIInput.Changeif you need it as it is typed.
Examples
Section titled “Examples”Ask for a name
Section titled “Ask for a name”Goal: greet the player once they type their name and press Enter.
#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: 20caps the name;clearable: trueadds a button that empties the field.UIInput::submitarrives when the player presses Enter, or the enter key of the in-scene keyboard, with the whole text inevent.data.text.- The script trims spaces, ignores an empty name, and tells other scripts with
emit.
A door code on a kiosk
Section titled “A door code on a kiosk”Goal: a numeric field with the in-scene keyboard; the right code opens the door, a wrong one shows a warning.
#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: trueshows the in-scene keyboard on a touch screen or desktop as well; in a headset it opens on its own.NotificationService.showraises a short toast at the top of the screen for each answer.setValue('')empties the field for the next try.
Filter a list as you type
Section titled “Filter a list as you type”Goal: hide the rows of a list that do not match the search text.
#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::changearrives 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.entityis each row’s entity.setEnabled(false)takes a row out of the list until it matches again. An empty search matches every row.
Components
Section titled “Components”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- |
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 |
|
virtual |
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.
UIInput::changeUIInput::submitUIInput::focusUIInput::blur
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 Input that greets the player as they type and confirms the name on Enter: a Behavior script listens to the field's change and submit events.
Click the field and type a name: the greeting follows each key. Press Enter to confirm it in green. 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 Input.
#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);}