A guide who greets you
Updated
Your first agent: an AI Agent with a persona and a dialog greets the visitor when the scene starts; the script listens to the agent’s signal and logs the finished reply.
Wait for the guide’s answer in the dialog and the log, then type into the dialog to keep talking. The guide needs the AI service: without it, the log says why it could not answer.
A guide who greets you
#pragma lifecycle(startup)
let reply = '';
async function startup() { const guide = findEntity('Guide'); const conversation = guide.getComponent(AIModelComponent).getConversation(); if (!conversation) { log('The guide is not available here.'); return; }
on('guide:ai', (event) => { if (event.eventType === EventType.AIAgent.Thinking) reply = ''; if (event.eventType === EventType.AIAgent.Writing) reply += event.data.text; if (event.eventType === EventType.AIAgent.Response) log('Guide said:', event.data.text); if (event.eventType === EventType.AIAgent.Error) log('Problem:', event.data.text); });
try { await conversation.send('Hello! Who are you, and what can I see here?'); } catch (error) { log('Could not ask the guide:', error.message); }}How it works
Section titled “How it works”The script is explained step by step in A guide who greets you.
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.
FirstAgent.xrproj