> 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-examples.md).

# 情绪示例

六个场景涵盖强制表情、过场锁定、基于分数的 VFX、偏移调节、中性重置和 Animation Blueprint 混合姿势。

以下场景展示了使用情绪系统的常见方式，适用于 `UConvaiChatbotComponent`。每个场景都是独立的，并假定角色已拥有可正常工作的 `Convai Chatbot` 组件。所有函数和属性的蓝图参考请参阅 [情绪蓝图参考](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/emotion/emotion-blueprint-reference.md).

***

### 场景 1：强制设置特定情绪

**情境：** 在脚本化的安全简报中，无论 Convai 发送什么内容，都需要虚拟指导员在特定时刻表现出担忧。

#### 蓝图步骤

1. 获取角色上 `Convai Chatbot` 组件的引用。
2. 调用 `Force Set Emotion`。将 **基本情绪** 设为 `Sad`, **强度** 设为 `More Intense`，并将 **重置其他情绪** 设为 `true`。应用的分数为 `1.0` （即 `More Intense` 乘数）。
3. `On Emotion State Changed` 会在调用完成后立即触发。如果你的处理程序会将分数映射到变形目标，请调用 `Get Emotion Score` 获取 `Sad` 的分数，并使用 `Set Morph Target`.

**验证：** `Get Emotion Score` 获取 `Sad` 时会返回 `1.0` ，角色的面部会通过映射的变形目标呈现悲伤表情。

{% hint style="info" %}
当 `On Emotion State Changed` 由 `Force Set Emotion`触发时， **交互玩家组件** 输出引脚为 `null`。在处理程序中使用该引脚之前，请先检查它是否为空。
{% endhint %}

***

### 场景 2：在过场动画期间锁定情绪状态

**情境：** 过场动画中必须让角色保持愤怒表情，同时 Convai 仍会发送由对话驱动的更新，而这些更新应被抑制。

#### 蓝图步骤

1. 过场动画开始前，调用 `Force Set Emotion` 并设置 **基本情绪** = `Angry`, **强度** = `Basic`, **重置其他情绪** = `true` 以设定所需的表情。
2. 将 `Lock Emotion State` 设为 `true` ，并在 `Convai Chatbot` 组件上启用。过场动画期间收到的所有服务器情绪更新都会被静默丢弃；锁定期间，服务器驱动的更新不会触发 `On Emotion State Changed` 事件。
3. 如果表情并非由事件处理程序驱动，请调用 `Get Emotion Score` 获取 `Angry` 的分数，并将返回值应用到相应的变形目标。
4. 过场动画结束后，将 `Lock Emotion State` 恢复为 `false`。下一次服务器情绪更新会替换锁定状态，并再次触发事件。

你也可以不先调用 `Force Set Emotion` ，直接将 `Lock Emotion State` 设为 `true` ，这样角色就会保持过场动画开始时的表情。过场动画结束后，将其重置为 `Force Set Emotion` ，直接将 `false` 。

**验证：** 过场动画期间，即使角色说话，愤怒表情也会保持不变。解锁后，新的语音会带来更新后的表情，并再次触发 `On Emotion State Changed` 事件。

***

### 场景 3：读取情绪分数以驱动视觉特效

**情境：** 角色周围的粒子系统应随着角色恐惧分数升高而增强——例如，在医疗培训模拟中使用代表角色陷入困境的视觉光环。

#### 蓝图步骤

1. 在角色蓝图中订阅 `On Emotion State Changed` 事件。
2. 在事件处理程序中，调用 `Get Emotion Score` 并将 **Emotion** 设为 `Afraid`。返回值是一个 `float` ，范围为 `0.0`–`1.0`.
3. 使用 **Rate Scale** 或 **Intensity** 参数，通过 `Set Float Parameter`.

同样的模式适用于任何 `EBasicEmotions` 值——利用该分数驱动 UI 仪表、材质参数、音高或任何其他数据驱动系统。

**验证：** 当角色说出带有恐惧情绪的内容时，粒子效果会随 `Afraid` 分数的变化而增强。

***

### 场景 4：通过偏移调节增强所有情绪

**情况：** 测试表明，在目标光照条件和预期摄像机距离下，角色的情绪过于微妙，难以清晰辨识。

#### 蓝图步骤

1. 在 `Convai Chatbot` 组件中选择 **Details** 面板。找到 **Emotion Offset** ，它位于 **Convai** 类别下。
2. 将其设为 `0.4` ，以便在限制到 `0.4` 之前，将后续所有由服务器驱动的分数计算结果提高 `0.0`–`1.0`.
3. 若要在运行时通过 Blueprint 设置此值，请获取聊天机器人组件的引用，从该引用拖出连线，然后使用 **Set** 节点设置 `Emotion Offset` 属性。

将 `Emotion Offset` 调低至 `0.0` 以下，可让角色表现得更加内敛，减弱所有表情。

**验证：** 与角色交谈后，在预期的摄像机距离下，面部表情会更加清晰，且 `获取情绪分数` 返回值高于偏移量更改前的值。

{% hint style="info" %}
`情绪偏移量` 仅适用于由服务器驱动的更新——对通过 `强制设置情绪`设置的分数无效。若要增强强制表情，请改为选择 `更强烈` 作为强度级别。
{% endhint %}

***

### 场景 5：恢复中性表情

**情况：** 在强制或锁定特定情绪的场景结束后，角色必须先恢复到完全中性的静止姿势，才能开始下一次交互。

#### 蓝图步骤

1. 在 `重置情绪状态` 上调用 `Convai 聊天机器人` 组件。此操作会将所有情绪分数归零。 `情绪状态已更改时` 随后会立即触发。
2. 在事件处理程序中（或重置后直接调用），对每个受驱动的情绪类别调用 `获取情绪分数` ——所有分数都将为 `0.0`.
3. 使用 `设置变形目标` 为每个映射的变形目标应用零权重。角色的面部将恢复到静止姿势。

**验证：** 读取到的所有情绪分数均为 `0.0` ，并且角色的面部会在下一次交互前恢复到默认静止姿势。

***

### 场景 6：在动画蓝图中驱动混合姿势

**情况：** 角色的表情应使用 Unreal 的姿势混合系统在不同姿势之间进行混合，而不是直接写入变形目标——例如，将情绪姿势与现有的移动或程序化动画相结合。

#### 蓝图步骤

1. 在角色的 **动画蓝图**中，添加一个名为 `SurpriseWeight` 的浮点变量（也可使用与目标情绪相符的任意名称）。
2. 在 **Event Blueprint Update Animation**中，获取所属 Actor 的引用，将其转换为你的角色类，然后获取 `Convai 聊天机器人` 组件。
3. 调用 `获取情绪分数` 并将 **情绪** 设置为 `Surprise`。将返回值连接到一个用于 **设置** 的节点，变量为 `SurpriseWeight`。这会在每个动画帧更新时运行。
4. 在 **AnimGraph**中，添加一个 **Blend Poses by float** 节点。将基础姿势连接到输入 **A**，将惊讶姿势（或 Pose Asset）连接到输入 **B**，并将 `SurpriseWeight` 连接到 **Alpha** 引脚。
5. 编译并在编辑器中运行（Play In Editor）进行测试。随着 `Surprise` 分数上升，角色会逐渐过渡到惊讶姿势。

这种方法会将表情混合保留在动画蓝图中，并且无需从事件处理程序调用 `Set Morph Target` 。你可以叠加多个 **Blend Poses by float** 节点（每种情绪类别一个），仅通过动画蓝图状态即可驱动完整的表情绑定。

**验证：** 在编辑器中运行（Play In Editor）时，对话过程中随着 `Surprise` 分数上升，角色会平滑地过渡到惊讶姿势。

***

### 相关页面

{% 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/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 %}


---

# 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-examples.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.
