For the complete documentation index, see llms.txt. This page is also available as Markdown.

角色动作快速入门

无需编写任何脚本,使用 ConvaiActionConfigSource、ConvaiActionDispatcher 和 TransformMoveToActionExecutor 为你的 NPC 添加可工作的 Move To 动作。

本指南将引导你连接一个“Move To”动作,使你的 NPC 在玩家请求时导航到场景中的对象。到最后,你的角色将能响应诸如“去箱子那里”这样的自然语言请求,并在场景中实际移动到它——无需代码。

先决条件

开始前,请确认:

配置动作管线

1

添加 ConvaiActionConfigSource

选择你的 NPC 的 GameObject。在 Inspector 中,点击 添加组件 并搜索 Convai Action Config Source (Convai/Convai Action Config Source).

你应该会在 Inspector 中看到四个新部分: 动作定义, 可操作对象, 可操作角色,以及 初始注意力.

Unity Inspector showing ConvaiActionConfigSource added to the NPC GameObject with the four configuration sections: Action Definitions, Actionable Objects, Actionable Characters, and Initial Attention
已将 ConvaiActionConfigSource 添加到 NPC——这四个部分现在可用于配置后端在运行时可引用哪些动作、对象和角色。
2

定义 Move To 动作

动作定义 列表中,点击 + 按钮以添加一项,然后填写这三个字段:

字段

动作名称

Move To

目标要求

对象

执行器

(暂时留空——下一步你会为它分配)

留空 超时秒数 位于 0 (无超时)。

Unity Inspector showing a Move To action definition in ConvaiActionConfigSource with Action Name set to Move To and Target Requirement set to Object
Move To 动作定义——动作名称与 Convai 发送的命令字符串匹配;目标要求 Object 会告诉分发器在调用执行器之前先解析一个场景对象目标。
3

注册一个目标对象

可操作对象 列表中,点击 + 并填写:

字段

名称

箱子

说明

左侧工作台旁的一个木质储物箱

GameObject 引用

将你的目标对象拖到这里

说明 会发送给 Convai,并帮助后端解析诸如“那个箱子”或“工作台旁边的那个东西”之类的模糊引用。请用一句自然的句子来写,让该对象处于上下文中。

Unity Inspector showing the Actionable Objects list on ConvaiActionConfigSource with a Crate entry including a descriptive name, description text, and a dragged-in GameObject reference
箱子已注册为可操作对象——Description 会发送给 Convai,并用于自然语言引用解析;GameObject Reference 保留在本地,绝不会传输。
4

添加 TransformMoveToActionExecutor

在同一个 NPC 上 GameObject,点击 添加组件 并搜索 Transform Move To Action Executor (Convai/Samples/Transform Move To Action Executor).

返回到 动作定义 你在上一步创建的条目。拖动 TransformMoveToActionExecutor 组件到 执行器 字段中。

Unity Inspector showing TransformMoveToActionExecutor added to the NPC and its component reference assigned to the Executor field in the Move To action definition
已将 TransformMoveToActionExecutor 分配为 Move To 执行器——这完成了动作到行为的绑定,Convai 选择 Move To 动作时分发器会使用它。
Executor field on the Move To action definition with TransformMoveToActionExecutor dragged in
将 TransformMoveToActionExecutor 拖到 Move To 动作定义中的 Executor 字段。
5

添加 ConvaiActionDispatcher

在同一个 NPC 上 GameObject,点击 添加组件 并搜索 Convai Action Dispatcher (Convai/Convai Action Dispatcher).

留空 批处理策略 位于 队列 是位于 失败策略 位于 停止批处理 ——这些是大多数场景下的正确默认值。

Unity Inspector showing ConvaiActionDispatcher added to the NPC GameObject with Batch Policy set to Queue and Failure Policy set to Stop Batch
已添加 ConvaiActionDispatcher——Queue 批处理策略和 Stop Batch 失败策略是大多数场景下的正确默认值,并且在此快速开始中无需进一步配置。

验证设置

你的 NPC 的 GameObject 现在应当具备这四个组件:

ConvaiCharacter
ConvaiActionConfigSource   ← 动作定义 + 目标对象
ConvaiActionDispatcher     ← 接收并执行批处理
TransformMoveToActionExecutor  ← 执行移动行为

进入 Play Mode,并说“去箱子那里”或“移动到箱子”。你的 NPC 应该会传送到箱子的位置。

如果你添加了 ConvaiActionDebugProbe (可选——见 角色动作故障排查),你也应该在 Console 中看到这一条:

[ConvaiActionDebugProbe] 步骤成功 #1:cmd='Move To crate',def='Move To',target=Object:Crate

如果 NPC 没有移动,请检查 角色动作故障排查 以查看诊断清单。

运行时行为

动作名称不区分大小写。 Move To, move to,以及 MOVE TO 都匹配同一定义。空格会保留—— Move To 是位于 MoveTO 不匹配。

配置会在会话开始时发送一次。 如果你在 Play Mode 中添加、重命名或移除动作或目标,请结束会话并重新连接,以使更改生效。

下一步

动作执行器编写自定义动作执行器配置角色动作

最后更新于

这有帮助吗?