Skip to content

AI Dialog

Updated

The visible conversation interface of the agent.

Type
ent-ai-dialog
Script class
AIDialogEntity

An AI Dialog entity is a chat panel on an entity of its own: a UI panel that shows the conversation of an AI Agent placed elsewhere in the scene, with the agent’s name, the latest exchange and a field to type or speak into. It holds no model and no conversation: it only presents those of the agent it points to.

Where it comes from. The AI Dialog entity is kept so that scenes saved with it still load and work. The Add menu does not offer it any more: a dialog is now an AI Dialog component added to the agent itself, which always presents that agent. You meet this entity when you open an older scene, and scripts can still find it, show and hide it, and change its settings.

What it is made of. The entity is a UI panel: a required UI Layout (in overlay render mode, arranging its content in a column) and a required UI Panel (its background box, with an opacity), plus the AI Dialog component that does the work. Because it is a panel, it also accepts the components panels take, such as a Billboard, a Follow Target or a Grabbable.

Editor and play. In the editor it is an inert preview: it shows the agent’s name and opens no conversation and no microphone. In play it binds to its agent’s conversation.

When to use it. For new work, add an AI Dialog component to the agent instead, and keep the standalone entity only in scenes that already have one. The last example on this page moves a standalone dialog’s settings onto its agent.

The props that matter most, on its AI Dialog component:

  • source and agentId tell the panel which agent to present. With source set to 'agent', the default, agentId holds the id of that AI Agent entity. These two props, and prompt, apply only to the standalone entity; on an agent, the dialog always presents its own agent.
  • presentation is 'always' (shown whenever it is enabled) or 'proximity' (shown while the player’s camera is inside the agent’s AI Proximity box).
  • microphone offers voice input in the composer, and autoSpeak speaks each finished reply through the agent’s AI Text To Speech.
  • subtitle is a line shown under the agent’s name. It is never sent to the model.
  1. Open the scene that holds the AI Dialog entity, and find it in the Hierarchy (see Scenes and hierarchy). Give it a clear name, such as Guide Dialog.
  2. Check that its AI Dialog component points to an AI Agent that is still in the scene, and that this agent has an AI Model.
  3. Set presentation, microphone, autoSpeak and subtitle as you would on an agent’s own dialog.
  4. Enter play and type a message: the agent’s reply appears in the panel.
  5. When you rework the scene, consider moving the dialog onto the agent, as in the last example below.

Hide the standalone dialog at startup and toggle it with the H key.

ToggleDialog.jx
#pragma lifecycle(startup, update)
// Scene: an AI Dialog entity named "Guide Dialog".
let panel;
function startup() {
panel = findEntity('Guide Dialog');
if (!(panel instanceof AIDialogEntity)) return log('No standalone dialog named Guide Dialog.');
panel.setEnabled(false);
}
function update() {
if (!panel) return;
if (Input.keyboard.isKeyReleased(Key.H)) panel.setEnabled(!panel.isEnabled());
}

How it works

  • instanceof AIDialogEntity checks that the entity found by name really is a standalone dialog.
  • setEnabled(false) switches off the whole entity, panel and dialog together. Disabling the dialog also stops any voice input, which never restarts by itself.
  • isKeyReleased is true for the one frame the key comes up, so one press toggles once.

Log what keeps the dialog from working, and give it a subtitle.

DialogCheck.jx
#pragma lifecycle(startup)
// Scene: an AI Dialog entity named "Guide Dialog".
function startup() {
const dialog = findEntity('Guide Dialog').getComponent(AIDialogComponent);
const agent = findEntity(dialog.props.agentId);
log('Presents:', agent ? AIPersonaComponent.displayName(agent) : 'no agent found');
dialog.setProps({ subtitle: 'Ask me about the collection', microphone: false });
const issue = dialog.getConfigurationIssue();
if (issue) log('Dialog problem:', issue);
}

How it works

  • dialog.props.agentId is the id of the agent the panel presents. findEntity accepts an id as well as a name.
  • AIPersonaComponent.displayName(agent) is the name the panel’s header shows: the agent’s persona name, else its entity name, else Agent.
  • setProps changes only the props it is given: here the subtitle, and microphone: false, which hides the Mic button and keeps typed chat.
  • getConfigurationIssue() returns a sentence describing what keeps the dialog from working, such as proximity presentation without an AI Proximity, or undefined when all is well.

Copy a standalone dialog’s settings onto its agent as an AI Dialog component, then switch the standalone entity off.

MigrateDialog.jx
#pragma lifecycle(startup)
// Scene: an AI Dialog entity named "Guide Dialog" that presents an AI Agent.
function startup() {
const panel = findEntity('Guide Dialog');
const old = panel.getComponent(AIDialogComponent);
const agent = findEntity(old.props.agentId);
if (!(agent instanceof AIAgentEntity)) return log('The dialog presents no agent in this scene.');
if (agent.getComponent(AIDialogComponent)) return log('The agent already has a dialog.');
const p = old.props;
agent.addComponent(new AIDialogComponent({
presentation: p.presentation,
subtitle: p.subtitle,
microphone: p.microphone,
autoSpeak: p.autoSpeak,
positioning: 'world',
panelOffset: { x: 0, y: 1.8, z: 0 },
billboard: true,
}));
panel.setEnabled(false);
log('The dialog now lives on', agent.name);
}

How it works

  • The script reads the old dialog’s props and builds a new AIDialogComponent with them; addComponent attaches it to the agent, which then presents itself.
  • source, agentId and prompt are left out: on an agent they do not apply.
  • positioning: 'world' places the panel at the agent’s position plus panelOffset, in metres, and billboard: true turns it to face the camera.
  • The standalone entity is switched off rather than destroyed, so nothing is lost if you need to compare. This runs each time the scene plays; to make the change permanent, add the component to the agent in the editor and delete the old entity.
  • A panel that presents no agent, because the agent was deleted or its id changed, shows nothing useful. getConfigurationIssue() and the agentId check above find it quickly.
  • In a headset, prefer world positioning: a screen panel follows the head.

What a new AI Dialog 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 Layout comp-ui-layout Required One Flexbox container that arranges child UI elements.
UI Panel comp-ui-panel Required One Background box of an element: fill, rounded corners, border.
AI Dialog comp-ai-dialog Starts with One The visible conversation interface of the agent.

You can also add 19 optional components, such as Animation Graph, Animation Timeline, Billboard, Dont Unload, Enable On Signal, Follow Target.

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
renderMode "overlay"
alignItems "stretch"
justifyContent "flex-start"
flexDirection "column"
Prop Default Range
opacity 1 0 ≤ x ≤ 1
Prop Default Range
autoSpeak false
microphone true
source "agent"
agentId ""
subtitle ""
prompt ""
presentation "always"
panelOffset {"x":0,"y":0,"z":0}
panelOrientation {"x":0,"y":0,"z":0}
positioning "world"
billboard false
screenAnchor "center"
insetX 0 -16384 ≤ x ≤ 16384
insetY 0 -16384 ≤ x ≤ 16384
screenScale 0.7 0.1 ≤ x ≤ 1
panelWidth 420 320 ≤ x ≤ 960
pixelSize 0.003 0.001 ≤ x ≤ 1

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

It reports the events every entity has: 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 AI Dialog.

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