> 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/convai-unreal-engine-plugin/features/emotion/emotion-quick-start.md).

# 情绪快速入门

将 Convai 角色的情绪分数连接到其 Skeletal Mesh 上的 morph target，使面部表情在对话期间自动更新。

我们将把 Convai 角色的情绪分数连接到其骨骼网格体上的变形目标，使角色交谈时面部表情自动更新。Convai 情绪数据默认在每个 `Convai Chatbot` 组件上启用——只有在你想自定义实现，将这些分数映射到角色骨骼网格体上的变形目标时，才需要遵循本指南。完成后，在编辑器中启动游戏并与角色交谈，即可实时看到表情变化。

### 你将构建的内容

一个蓝图事件处理程序，每当 `UConvaiChatbotComponent` 从 Convai 接收到新的情绪状态时就会触发，并使用 `Get Emotion Score`读取各情绪的分数，再使用 `Set Morph Target`.

### 前提条件

开始之前，请确认：

* 已安装 Convai Unreal Engine 插件，并配置了 API 密钥。
* 关卡中有一个角色 Actor，并且其 `Convai Chatbot` 组件可以正常工作（与角色交谈时，角色已经能够说话）。
* 角色的骨骼网格体包含你想驱动的情绪对应的变形目标——请在骨骼网格体资源编辑器中查看 **Morph Targets** 选项卡，并记下准确名称。

{% hint style="info" %}
如果角色尚未设置，请先完成 [添加你的第一个角色](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/getting-started/add-your-first-convai-character.md) ，然后再回到这里。
{% endhint %}

### 在蓝图中绑定事件

{% stepper %}
{% step %}

#### 打开角色 Blueprint

在 **内容浏览器**中，打开角色 Actor 的蓝图。切换到 **事件图表**.
{% endstep %}

{% step %}

#### 添加 On Emotion State Changed 事件

在事件图表中右键单击并搜索 `On Emotion State Changed`。选择列在你的 `Convai Chatbot` 组件下方的事件。此时会出现一个包含两个输出引脚的事件节点： **聊天机器人组件** 和 **交互玩家组件**.
{% endstep %}

{% step %}

#### 读取情绪分数

从 **聊天机器人组件** 输出引脚拖出连线，并搜索 `Get Emotion Score`。将 **Emotion** 设置为你想先驱动的类别，例如，将 `Happy` 用于微笑变形目标。返回值是一个 `float` ，范围为 `0.0`–`1.0`.

对于网格体支持的每个 `EBasicEmotions` 类别，重复调用此函数；也可以先从一种情绪开始，验证整个流程后再添加其余情绪。
{% endstep %}

{% step %}

#### 将分数应用于变形目标

对于每个 `Get Emotion Score` 返回值，添加一个 `Set Morph Target` 节点。将 **Target** 连接到角色的 **Skeletal Mesh Component**，将 **Morph Target Name** 设为 Skeletal Mesh **Morph Targets** 选项卡中的准确名称，并将分数连接到 **Value**.
{% endstep %}

{% step %}

#### 编译并保存

在 Blueprint 编辑器工具栏中点击 **Compile** ，然后点击 **Save** 。

现在事件已连接完成。每当角色从 Convai 接收到新的情绪状态时，处理程序就会触发，并更新你映射的变形目标。
{% endstep %}
{% endstepper %}

{% hint style="success" %}
**预期结果：** Blueprint 图表中显示 `On Emotion State Changed` → 一个或多个 `Get Emotion Score` → `Set Morph Target` 调用链，且全部连接正常、没有错误。Blueprint 编译成功。
{% endhint %}

### 运行角色

进入编辑器内运行模式（Play In Editor）并开始对话。与角色交谈并观察其面部——角色根据不同的情绪内容作出回应时，表情应随之变化。

如果表情没有变化，请按以下清单检查：

* &#x20;`Convai Chatbot`  组件具有有效的 **Character ID** ，并且插件能够连接到 Convai。
* 事件 `On Emotion State Changed` 会触发——在处理程序中添加一个 `Print String` 节点进行验证。如果它从未触发，说明会话未连接，或 Convai 未发送情绪数据。
* `Get Emotion Score` 在角色说话时会返回大于 `0.0` 的值——在分数节点后添加 `Print Float` 以确认。
* 将 **Morph Target Name** 在每个 `Set Morph Target` 节点与角色骨骼网格体上的名称完全匹配（区分大小写）。

请参阅 [排查情绪问题](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/emotion/troubleshoot-emotion.md) ，了解详细指导。

#### 工作原理

当你与角色交谈时， `UConvaiChatbotComponent` 接收了 Convai 的情绪信号，将服务器标签映射为一个 `EBasicEmotions` 值，根据服务器的刻度（`scale / 3` 加上 `EmotionOffset`）计算浮点分数，并触发 `On Emotion State Changed`。你的处理程序读取这些分数，并将其应用到骨骼网格体上。有关各个阶段的完整说明，请参阅 [情绪系统的工作原理](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/emotion/how-the-emotion-system-works.md).

将每个 `EBasicEmotions` 类别映射到绑定骨架上已有的变形目标名称。MetaHuman 和 Reallusion 设置通常采用不同的命名约定——请直接从 **变形目标** 选项卡中复制名称，而不要假设名称列表固定不变。

### 后续步骤

{% content-ref url="/pages/c3081281b873e1a1b00439a147d3db6877743003" %}
[情绪系统的工作原理](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/emotion/how-the-emotion-system-works.md)
{% endcontent-ref %}

{% content-ref url="/pages/9ac48061a03a0400ae6e1769df358c2fb2a82536" %}
[情绪 Blueprint 参考](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/emotion/emotion-blueprint-reference.md)
{% endcontent-ref %}

{% content-ref url="/pages/83566839f3555aa1855858bb1bc0c20ed5a973cc" %}
[情绪示例](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/emotion/emotion-examples.md)
{% endcontent-ref %}


---

# 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/convai-unreal-engine-plugin/features/emotion/emotion-quick-start.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.
