> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/unity-plugin-beta-overview/features/actions.md).

# 动作

让 AI 角色能够根据玩家所说的话采取行动。涵盖完整的动作系统——架构、配置、执行器和运行时控制。

本旧版章节介绍的是早期的 Unity Actions 工作流。

{% hint style="warning" %}
**已于 2026 年 8 月 26 日弃用。** 请参阅 [角色动作](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/character-actions.md) ，了解当前 Convai Unity SDK 文档中的相关内容。本章节仍供尚未迁移的项目使用。
{% endhint %}

## 什么是动作？

Convai 动作让 AI 角色不仅能说话，还能 **执行操作**。当玩家说“走到箱子旁边”或“挥手问好”时，Convai 会从你定义的菜单中选择合适的行为和目标。随后，SDK 会直接在 Unity 场景中执行该行为——常见用例无需编写脚本。

动作是对话与游戏玩法之间的桥梁。你无需编写关键词检测逻辑，也无需为 NPC 的每种可能回应编写脚本，只需一次性声明一组可能的行为，其余工作由 AI 处理。

## 工作原理

玩家与 Convai 角色交谈时，以下流程会自动发生：

```mermaid
flowchart LR
    A([玩家说话\n或输入文字]) --> B[Convai\n选择动作 + 目标]
    B --> C[ConvaiActionDispatcher\n接收命令批次]
    C --> D{按动作名称\n查找定义}
    D -->|找到| E[在场景中\n解析目标]
    E --> F[执行器运行\n该行为]
    F --> G([结果：\n成功 / 失败])
    D -->|未找到| H([跳过此步骤\n或中止批次])
```

从接收命令到执行行为，整个流程都由 SDK 处理。你只需定义可用的动作，并为每个动作指定合适的执行器组件。

## 关键概念

| 概念         | 术语说明                                          |
| ---------- | --------------------------------------------- |
| **动作**     | 角色可以执行的具名行为（例如， `Move To`, `Wave`, `Pick Up`) |
| **目标**     | 动作所指向的场景对象或角色（例如， `Crate`, `Guard`)           |
| **执行器**    | 负责在 Unity 场景中执行行为的 MonoBehaviour 组件           |
| **分发器**    | `ConvaiActionDispatcher` — 接收动作命令并调用相应的执行器    |
| **批次**     | 一次后端响应返回的动作列表（例如，走到架子旁，然后拿起头盔）                |
| **定义**     | Inspector 中的条目，用于将动作名称映射到执行器，并指定目标要求          |
| **对象指代消解** | 后端根据描述和当前关注对象，将模糊指代（“它”“那个”）解析为特定场景对象的过程      |

## 各组件的放置位置

NPC 的 GameObject 上有两个组件协同工作：

| 组件                         | 用途                  |
| -------------------------- | ------------------- |
| `ConvaiActionConfigSource` | 在此定义可用的动作、对象和角色     |
| `ConvaiActionDispatcher`   | 接收后端发送的命令，并运行匹配的执行器 |

这两个组件都必须与 **位于同一个 GameObject 上** ，与 `ConvaiCharacter`.

## 本章节内容

<table data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>快速入门</strong></td><td>通过分步讲解，几分钟内即可让你的第一个动作运行起来。</td></tr><tr><td><strong>配置动作</strong></td><td>在 Inspector 中定义动作、注册目标并微调行为。</td></tr><tr><td><strong>动作执行器</strong></td><td>了解 SDK 附带的所有执行器，并学习各自的适用场景。</td></tr><tr><td><strong>分发器与批处理策略</strong></td><td>控制分发器在运行时如何安排动作顺序并处理动作批次。</td></tr><tr><td><strong>编写自定义执行器</strong></td><td>使用 C# 构建自己的执行器，实现所需的任意游戏行为。</td></tr><tr><td><strong>注意力与指代消歧</strong></td><td>了解对象描述和注意力对象如何帮助 AI 理解玩家含糊不清的指代。</td></tr><tr><td><strong>调试与故障排查</strong></td><td>使用内置调试探针和分步检查清单诊断问题。</td></tr></tbody></table>

## 使用当前角色动作指南

Convai Actions 将自然对话与游戏内行为连接起来。你可以定义角色 *能够* 做什么——由 AI 决定 *何时* 以及 *为何* 这样做。本节中的页面将引导你完成从实现第一个可运行的动作，到使用 C# 编写完全自定义执行器的全过程。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/unity-plugin-beta-overview/features/actions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
