> 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/how-the-emotion-system-works.md).

# 情绪系统的工作原理

了解 Convai 如何以每种情绪的分数形式传递情绪状态，服务器比例如何映射到分数值，以及偏移和锁定控件的作用。

当 Convai 角色回复时，Convai 会分析生成的语音，并在返回音频的同时发送情绪状态。Convai Unreal Engine 插件会将该状态存储在 `UConvaiChatbotComponent`上，通过蓝图公开各情绪的浮点分数，并在状态每次更新时触发事件。

### 关键概念

| 概念                           | 说明                                                                                         |
| ---------------------------- | ------------------------------------------------------------------------------------------ |
| `UConvaiChatbotComponent`    | 用于管理单个角色情绪状态的蓝图组件。分数和状态相关 API 均位于此组件中。                                                     |
| `EBasicEmotions`             | 包含七种可见情绪类别的枚举（`Happy`, `Calm`, `Afraid`, `Surprise`, `Sad`, `Bored`, `Angry`).             |
| `EEmotionIntensity`          | 包含三个强度等级的枚举（`Less Intense`, `Basic`, `More Intense`），由 `Force Set Emotion` 使用，而不用于服务器分数路径。 |
| `EmotionOffset`              | 一个 `float` 偏移值，会在服务器驱动的每个情绪分数限幅前将其加上。用于提高或降低感知到的情绪强度。                                      |
| `LockEmotionState`           | 一个 `bool` 标志，用于阻止传入的服务器情绪更新，并在服务器路径上抑制 `On Emotion State Changed` 事件，直到解除锁定。               |
| `OnEmotionStateChangedEvent` | 当情绪状态发生变化时，在游戏线程上触发的委托，是蓝图表情逻辑的主要挂接点。                                                      |
| `GetEmotionScore`            | 返回某个 `float` 分数（`0.0`–`1.0`），对应一个 `EBasicEmotions` 类别。可使用此分数驱动形态目标或动画蓝图变量。                 |

### 情绪类别

该插件通过 `EBasicEmotions`:

| 枚举值   | 蓝图显示名称 |
| ----- | ------ |
| `Joy` | `快乐`   |
| `信任`  | `平静`   |
| `恐惧`  | `害怕`   |
| `惊讶`  | `惊讶`   |
| `悲伤`  | `难过`   |
| `厌恶`  | `无聊`   |
| `愤怒`  | `生气`   |

当前 `bot-emotion` 数据包路径会在每次更新时提供一个情绪标签和一个量表值。除非 `LockEmotionState` 为 `true` （参见 [锁定情绪状态](#locking-emotion-state)).

### 服务器情绪标签

服务器会发送一个简短的情绪标签字符串，以及一个强度量表（`1`–`3`）。插件会通过 `EBasicEmotions` 将这些标签映射到枚举值，使用 `GetTTSEmotion`。可识别的八个标签如下：

| 服务器标签  | 映射到（`EBasicEmotions`) |
| ------ | --------------------- |
| `"喜悦"` | `Joy`                 |
| `"平静"` | `信任`                  |
| `"恐惧"` | `恐惧`                  |
| `"惊讶"` | `惊讶`                  |
| `"悲伤"` | `悲伤`                  |
| `"无聊"` | `厌恶`                  |
| `"愤怒"` | `愤怒`                  |
| `"中性"` | `None` （没有活跃情绪）       |

收到服务器更新时，插件会先重置所有情绪分数，然后写入已解析类别对应的分数。插件无法识别的标签会映射为 `None` ——分数仍会被重置，因此角色会恢复为中性分数表，而不是保留之前的表情。如果对话过程中始终没有出现某种特定情绪，请确认 Convai 发送的是上面列出的某个标签——参见 [排查情绪问题](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/emotion/troubleshoot-emotion.md).

### 情绪分数

每个类别都带有一个范围为 `0.0`–`1.0`的浮点数分数。使用 `Get Emotion Score` (`EBasicEmotions Emotion`) 在 `UConvaiChatbotComponent`.

#### 由服务器驱动的分数

在服务器路径中，插件会解析 `bot-emotion` 数据包中的情绪字符串和量表，将量表除以 `3`，再加上 `EmotionOffset`，并将结果限制在 `0.0`–`1.0`。刻度为 `1` 大约得到 `0.33` （偏移前）；刻度为 `3` 得到 `1.0` （偏移前）。

该 `EEmotionIntensity` 乘数（`0.25`, `0.60`, `1.00`) 仅适用于 `Force Set Emotion`，而非由服务器驱动的更新。

#### EmotionOffset

&#x20;`EmotionOffset`  `UConvaiChatbotComponent` 会在收到由服务器驱动的情绪更新时，将所有计算出的分数统一调整一个固定值。源代码注释指出，一个实用的范围是 `-1` 到 `1`:

* 正偏移量会增强每种情绪的感知强度。
* 负偏移会降低其数值。
* 分数始终会限制在 `0.0`–`1.0` （应用偏移后）。

`EmotionOffset` 仅适用于服务器驱动的更新。它 **不** 适用于通过 `Force Set Emotion` 设置的分数——该函数使用 `EEmotionIntensity` 倍数。

### 将分数应用到面部

在服务器情绪路径中，插件不会填充现成的变形目标映射。要显示表情，请使用以下节点读取分数： `Get Emotion Score` 然后使用以下节点将分数应用到变形目标： `Set Morph Target` 也可以在蓝图中使用这些节点，或根据分数变量驱动动画蓝图混合姿势。将每个 `EBasicEmotions` 类别映射到角色骨骼网格体上的变形目标名称。

### 锁定情绪状态

将 `LockEmotionState` 设为 `true` 后， `UConvaiChatbotComponent` 会阻止传入的服务器更新更改当前情绪。在服务器路径中， `OnEmotionReceived` 会在更新状态或广播 `On Emotion State Changed`之前返回，因此锁定生效期间，服务器驱动的更新不会触发该事件。

状态会保持应用锁定时的值——无论该值来自之前的服务器更新，还是来自 `Force Set Emotion` 调用——直到将 `LockEmotionState` 重新设为 `false`. `Force Set Emotion` 。即使处于锁定状态， `Reset Emotion State` 仍会更新状态并触发事件。

如果你希望角色在过场动画或电影片段期间保持特定表情，不受 Convai 发送的内容影响，这项功能就很有用。

{% hint style="warning" %}
请确认 `LockEmotionState` 在任何锁定流程结束后都重置为 `false` ，否则角色会一直保持锁定的表情，直到你解除锁定。
{% endhint %}

### 强制设置情绪

`Force Set Emotion (EBasicEmotions BasicEmotion, EEmotionIntensity Intensity, bool ResetOtherEmotions)` 可在蓝图中覆盖情绪状态，无需等待服务器更新。当 `ResetOtherEmotions` 为 `true`时，会先将所有其他情绪分数归零。当 `false`时，强制设置的分数会替换相同类别的分数，并保留其他类别不变。

应用的分数等于所选级别对应的 `EEmotionIntensity` 乘数（`Less Intense` = `0.25`, `Basic` = `0.60`, `More Intense` = `1.00`). `EmotionOffset` 不会应用。

### 状态更改事件

`On Emotion State Changed` 会在游戏线程上触发，条件是情绪状态由服务器更新（未锁定时）、由 `Force Set Emotion`或由 `Reset Emotion State`。其签名会返回聊天机器人组件和交互玩家组件引脚——在当前插件中， **交互玩家组件** 输出始终为 `null` （适用于所有路径）。使用前请对该引脚进行空值检查。

下图展示了从服务器发送数据、计算分数到 Blueprint 处理程序的完整流程：

```mermaid
graph TD
    A["Convai"] -- "情绪标签 + 1–3 的强度值" --> B["标签 → EBasicEmotions\n映射"]
    B -- "强度值 / 3 + EmotionOffset\n限制在 0–1 之间" --> C["UConvaiChatbotComponent\nEmotionState"]
    C -- "OnEmotionStateChangedEvent" --> D["Blueprint 处理程序"]
    D -- "GetEmotionScore()" --> E["设置 Morph Target / AnimBP"]
    F["强制设置情绪"] -- "EEmotionIntensity\n乘数（不含偏移量）" --> C
    G["LockEmotionState = true"] -- "阻止服务器路径" --> C
```

### 相关页面

{% 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/how-the-emotion-system-works.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.
