Dialog and captions
Updated
An agent needs a face on screen. The AI Dialog is its chat panel: the agent’s name, the latest exchange, and a field to type or speak into. The AI Caption shows subtitles of the speech the agent hears and says. The AI Proximity is an invisible box around the agent that notices when the player walks in or out, so the panel can open on approach and the agent can greet them. All three are presentation: they read the agent’s shared conversation and never change what the model answers.
Before you start
Section titled “Before you start”- You have an agent with an AI Model, and ideally an AI Persona. See Creating an agent.
- The panels are UI. Screen and world placement work as for any panel; see UI.
- Scripts react to the panels through the agent’s Signal Emitter. See Scripting AI.
AI Dialog
Section titled “AI Dialog”The AI Dialog (comp-ai-dialog, AIDialogComponent) goes on the agent. From top to bottom the panel holds:
A standalone AI Dialog entity above a desk presents the conversation of a guide standing elsewhere in the room: its dialog names the agent by id.
The panel over the desk is Ada's conversation, though Ada stands across the room. Type a message to try it. Replies need the AI service, which this preview does not have: a message you send shows a short error in the panel instead. Drag outside the panel to orbit the camera, scroll to zoom.
- Header. An avatar tile, the agent’s display name (its Persona’s name, else the entity’s name, else
Agent), and the optionalsubtitle. - Language button. Shown when the agent has an enabled AI Translation. It opens a menu to switch translation on and pick a language. See Translation and memory.
- Messages. The latest visitor message and the agent’s reply, each scrolling when it is long. While a new turn runs, the panel shows progress. An empty panel says “Hi! How can I help?”.
- Play button. Next to a finished reply when the agent has an enabled AI Text To Speech: it speaks the reply, and turns into Stop while it plays.
- Composer. A text field that grows to three lines. Empty, it offers Mic (when
microphoneis on). With text, it offers Send. During a turn it offers Stop, which cancels the reply and keeps your next draft.
When a turn fails, the panel keeps the conversation and the draft and shows a short message. Replies are shown as readable plain text: formatting marks such as headings and list markers are turned into ordinary text.
| Prop | Type | Default | Description |
|---|---|---|---|
presentation |
'proximity' or 'always' |
'always' |
Show the panel always, or only while the player’s camera is inside the agent’s AI Proximity box. |
subtitle |
string | '' |
A line under the name. Never sent to the model. |
microphone |
boolean | true |
Offer voice input in the composer. |
autoSpeak |
boolean | false |
Speak each finished reply through AI Text To Speech. |
positioning |
'world' or 'screen' |
'world' |
Place the panel in the world next to the agent, or pinned to the screen. |
panelOffset |
{ x, y, z } in metres |
{ x: 0, y: 0, z: 0 } |
World only: offset from the agent, in its local space. |
panel |
{ x, y, z } in radians |
{ x: 0, y: 0, z: 0 } |
World only: extra rotation, applied after billboarding. |
billboard |
boolean | false |
World only: turn the panel to face the camera. |
screenAnchor |
'top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom' or 'bottom- |
'center' |
Screen only: the point of the viewport the panel is pinned to. |
insetX, insetY |
number, px | 0, 0 |
Screen only: offset from the anchor. |
screenScale |
number | 0.7 |
Screen only: size on screen, 0.1 to 1. |
panelWidth |
number, px | 420 |
Panel width in layout pixels, 320 to 960. |
pixelSize |
number, m per px | 0.003 |
World only: metres per layout pixel. |
background |
string | the theme’s dialog surface | Panel fill. Accepts #RRGGBBAA, rgba(…) and transparent; alpha fades the fill only, not the text. |
textColor |
string | the theme’s text colours | Text colour override. Clear it to follow the theme. |
font |
string | the project’s UI font | Font family of every text in the panel, by name. |
Placement. In world, the panel sits at the agent’s origin plus panelOffset, and scales with pixelSize. In screen, it is pinned to the viewport at screenAnchor plus the insets; in a headset a screen panel follows the head, so prefer world for XR. Placement never moves the agent itself.
Microphone. With microphone: true, an empty composer shows Mic. It stays visible but disabled, with a tooltip saying why, while the agent has no enabled AI Speech To Text, its sources lack 'microphone', or the application turns the microphone off. Showing the dialog never opens the microphone; hiding or disabling it stops voice input, which never resumes by itself.
| Member | What it does |
|---|---|
set |
Show or hide the panel. Enabled, it shows in always presentation or follows the Proximity box. Disabled, it hides and cancels only its own automatic work. |
set |
Change any of the props above. Placement, colour and font edits update the panel in place. |
get |
A sentence describing what keeps the dialog from working, such as a missing Proximity in proximity presentation, or undefined. |
Opening a dialog without code
Section titled “Opening a dialog without code”A button can open a dialog with no script:
- On the agent, set the dialog’s
presentationtoalwaysand save the dialog disabled. - On the button, add a Signal Emitter with
signal: guide/openandeventFilter: [UIButton::press]. - On the agent, add an Enable On Signal with
signal: guide/open,action: enableandtargetFilter: [AIDialog].
A press now enables the dialog in play. Use action: toggle for one open and close button.
AI Caption
Section titled “AI Caption”The AI Caption (comp-ai-caption, AICaptionComponent) shows subtitles of what the agent’s AI Speech To Text recognizes: the agent’s own speech, and any other audio its sources select. Without Speech To Text it shows nothing, and typed text never becomes a caption.
An AI Caption shows what the guide's AI Speech To Text hears: her own lines spoken through the browser's voice, and the Radio, which an AI Speech Capture marker selects for transcription.
Press Next line: the guide speaks with your browser's voice and her caption appears above her, also in the log. Transcribing the Radio needs the AI service, which this preview does not have: the log reports it instead. Drag outside the panel to orbit the camera.
- It shows the current line only, in a two-line window. A finished line stays for 6 seconds, and a new line restarts that time.
- Pausing, muting or cancelling speech clears it at once.
- With translation on, finished lines are translated before they show.
- Captions are never saved. Removing the caption leaves recognition running.
| Prop | Type | Default | Description |
|---|---|---|---|
positioning |
'world' or 'screen' |
'world' |
Placement, as for the dialog. |
panelOffset |
{ x, y, z } in metres |
{ x: 0, y: 0. |
World only: offset from the agent. |
panel |
{ x, y, z } in radians |
{ x: 0, y: 0, z: 0 } |
World only: extra rotation. |
billboard |
boolean | false |
World only: face the camera. |
screenAnchor |
one of the nine anchors | 'bottom' |
Screen only. |
insetX, insetY |
number, px | 0, 22 |
Screen only: offset from the anchor. |
screenScale |
number | 0.7 |
Screen only: size on screen, 0.1 to 1. |
panelWidth |
number, px | 340 |
Width in layout pixels. |
pixelSize |
number, m per px | 0.002 |
World only: metres per layout pixel. |
fontSize |
number, px | 16 |
Text size. |
font |
string | the project’s UI font | Font family. |
color |
string | '#ffffff' |
Text colour. |
background |
string | the theme’s dialog surface | Panel fill; transparency allowed. |
padding |
number, px | 22 |
Inner padding. |
textAlign |
'left', 'center' or 'right' |
'center' |
Text alignment. |
Colour, font and placement edits update the caption in place without dropping the current line.
AI Proximity
Section titled “AI Proximity”The AI Proximity (comp-ai-proximity, AIProximityComponent) is a box around the agent that follows the active camera: the player is “inside” while the camera is in the box. It needs no collider and no character controller. Add it to the agent and set the dialog’s presentation to proximity, and the panel shows only while the player is near.
| Prop | Type | Default | Description |
|---|---|---|---|
halfExtents |
{ x, y, z } in metres |
{ x: 1, y: 1, z: 1 } |
Half the box’s size along each axis, in the agent’s local space: the default is a 2 m cube. |
enterPrompt |
string | '' |
Sent to the agent as a hidden command when the player walks in. Empty sends nothing. |
leavePrompt |
string | '' |
Sent as a hidden command when the player walks out. Empty sends nothing. |
In play, each crossing sends its non-empty prompt through the agent’s conversation as a command: the visitor does not see the prompt, but sees the agent’s reply, which is spoken like any other. The latest crossing wins: walking out cancels a greeting still being written. A turn your script started is never cancelled by a crossing.
| Member | What it does |
|---|---|
getSnapshot() |
{ inside, available }: whether the camera is in the box, and whether the box is working. |
subscribe(listener) |
Call listener() each time the snapshot changes. Returns the function that stops it. |
send |
Send the configured enter or leave prompt yourself. |
| Event | Data | When |
|---|---|---|
AIProximity::enter |
{ inside } |
The camera entered the box. |
AIProximity::exit |
{ inside } |
The camera left it. |
The events go to the Signal Emitters on the agent. In the editor, a selected agent draws the box as a translucent outline.
Examples
Section titled “Examples”1. Open the dialog from a button
Section titled “1. Open the dialog from a button”#pragma lifecycle(startup)
function startup() { const dialog = findEntity('Guide').getComponent(AIDialogComponent); log('The dialog starts', dialog.enabled ? 'open' : 'closed');
on('guide/open', (event) => { if (event.eventType !== EventType.UIButton.Press) return; dialog.setEnabled(!dialog.enabled); log('The dialog is now', dialog.enabled ? 'open' : 'closed'); const issue = dialog.getConfigurationIssue(); if (issue) log('The dialog cannot work yet:', issue); });}A UI button opens and closes an AI agent's chat panel: the AI Dialog is saved disabled and a Behavior script toggles it, checking getConfigurationIssue for anything missing.
Press Talk to the guide to open the panel, and again to close it. Opening it needs no AI service; replies need one. Drag to orbit the camera, scroll to zoom.
dialog.enabledreads the current state, so one button opens and closes the panel.getConfigurationIssue()explains what is missing, for example a Proximity box inproximitypresentation, which is far easier than guessing why nothing shows.
2. Move the dialog onto the screen
Section titled “2. Move the dialog onto the screen”#pragma lifecycle(startup)
// Scene: an AI Agent named "Guide" with an AI Dialog and an AI Caption,// and a UI Switch "Pin to screen" with a Signal Emitter on 'settings:pin'.function startup() { const guide = findEntity('Guide'); const dialog = guide.getComponent(AIDialogComponent); const caption = guide.getComponent(AICaptionComponent);
dialog.setProps({ subtitle: 'Ask me about the collection', billboard: true, panelOffset: { x: 0, y: 0.4, z: 0 } });
on('settings:pin', (event) => { if (event.eventType !== EventType.UISwitch.Change) return; if (event.data.checked) { dialog.setProps({ positioning: 'screen', screenAnchor: 'bottom-right', insetX: 24, insetY: 24, screenScale: 0.8 }); caption.setProps({ positioning: 'screen', screenAnchor: 'bottom', insetY: 22 }); } else { dialog.setProps({ positioning: 'world' }); caption.setProps({ positioning: 'world' }); } });}A switch moves a guide's AI Dialog panel and AI Caption between the world, above the guide, and the screen's corner, keeping the world placement for the way back.
Turn on Pin to screen to move the dialog panel to the bottom-right corner of the screen, and off to bring it back above the guide. Moving it needs no AI service; replies need one.
- The world values (
billboard,panelOffset) are kept while the panel is on the screen, so switching back restores the old placement. - Insets are in screen pixels from the anchored corner, like a CSS margin.
3. Greet the player on approach
Section titled “3. Greet the player on approach”#pragma lifecycle(startup)
function startup() { const guide = findEntity('Guide'); const proximity = guide.getComponent(AIProximityComponent); const hint = findEntity('Talk Hint');
proximity.setProps({ halfExtents: { x: 3, y: 2, z: 3 }, enterPrompt: 'The visitor just walked up. Greet them in one sentence.', leavePrompt: '', });
hint.visible = !proximity.getSnapshot().inside;
on('guide:ai', (event) => { if (event.eventType === EventType.AIProximity.Enter) hint.visible = false; if (event.eventType === EventType.AIProximity.Exit) hint.visible = true; });}An AI Proximity box round the guide shows her dialog only while the camera is near, and a Behavior script hides the "walk up" hint on the proximity's enter event.
Hold W to walk the camera inside the blue ring: the hint goes and the guide's dialog appears. Hold S to walk back out. The greeting itself is sent to the AI service, which this preview does not have, so the panel shows a short error instead of a reply.
- The
enterPromptgreeting is sent automatically on each entry. The script does not send it again: it only reacts to the crossing by hiding a hint. getSnapshot()gives the state at startup, before any crossing happens.- AI Proximity events reach the same Signal Emitter as the agent’s own events, so one listener handles both.
Snippets
Section titled “Snippets”1. Style the captions
Section titled “1. Style the captions”#pragma lifecycle(startup)
// Scene: an AI Agent named "Guide" with AI Speech To Text and an AI Caption.function startup() { const caption = findEntity('Guide').getComponent(AICaptionComponent); caption.setProps({ positioning: 'screen', screenAnchor: 'bottom', insetY: 40, panelWidth: 600, fontSize: 22, color: '#fde68a', backgroundColor: 'rgba(15, 23, 42, 0.75)', textAlign: 'center', });}- A wide, screen-anchored caption at the bottom reads like film subtitles.
backgroundColoraccepts transparency, so the scene shows through behind the text.
Common mistakes
Section titled “Common mistakes”proximitypresentation without a Proximity box. The panel never shows. Add an AI Proximity to the same agent, or checkgetConfigurationIssue().- Sending the greeting twice. The Proximity already sends
enterPrompton entry. A script that also callsconversation.sendonAIProximity::entermakes the agent greet twice, or fails because a turn is running. - Captions without Speech To Text. The caption shows what speech recognition hears; typed chat never becomes a caption.
- Screen panels in XR. A screen-positioned panel follows the head in a headset. Use
worldwithbillboard: truefor headsets. - Expecting a title prop. The header shows the Persona’s name. Change the name on the AI Persona, and use
subtitlefor extra text.