A name field
Updated
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.
A name field
#pragma lifecycle(startup)
function startup() { const input = findEntity('Name').getComponent(UIInputComponent); const greeting = findEntity('Greeting').getComponent(UILabelComponent);
input.setProps({ text: 'Your name', placeholder: 'Type and press Enter', maxLength: 20, clearable: true });
on('profile:name', (event) => { if (event.eventType === EventType.UIInput.Change) { greeting.setProps({ text: event.data.text ? `Hello, ${event.data.text}…` : '' }); } if (event.eventType === EventType.UIInput.Submit) { const name = event.data.text.trim(); if (!name) return; greeting.setProps({ text: `Welcome, ${name}!`, color: '#4ade80' }); emit('profile/named', { name }); } });}How it works
Section titled “How it works”The script is explained step by step in A name field.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
NameField.xrproj