> 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-unity-sdk/features/multi-character-sessions/how-multi-character-sessions-work.md).

# 多角色会话工作原理

了解包含多个 Convai 角色的 Unity 场景如何变成一个共享房间，以及房间如何决定玩家正在对谁说话。

一个 Convai 房间可以容纳不止一个角色。本页将解释一个包含多个 `ConvaiCharacter` 组件的场景如何变成一个共享房间，这个房间如何决定玩家正在和谁说话，以及为什么一次只有一个角色发言。

### 两个或更多角色就是完整的设置

一个房间会容纳所有处于激活状态的 `ConvaiCharacter` ，并且位于已加载场景中。无需开启多角色模式，无需添加组件，也无需填写任何字段——只要场景中存在，房间就会容纳不止一个角色。之所以无需配置，是因为单角色场景和多角色场景走的是同一条连接路径；唯一的区别在于该路径运行时会找到多少个处于激活状态的角色。

该 **Convai Manager** 组件会直接反映这一点。其 **场景设置** 部分会自动检测场景中的每一个 `ConvaiCharacter` ，并为每个角色列出一个复选框，另外还有一个 **包括全部** 按钮，可一次性全部选中。列表中的内容没有任何手动绑定——它是场景当前已有内容的实时视图。

### 房间会先对一个角色开放

在玩家还没有查看或说任何话之前，房间就会先对一个角色开放，因为对话总得从某处开始。决定是哪一个角色的因素有两个：

* 已指定的 **初始角色** 在 Convai Manager 检视器中会直接胜出。无论场景顺序如何，也不管玩家摄像机此刻朝向哪里，房间都会先对那个角色开放。
* 如果没有 **初始角色** 被指定，房间就会先对场景顺序中的第一个角色开放。

已指定的 **初始角色** 只决定对话 *开始*的位置。从房间准备就绪的那一刻起，下面这条规则会以大约每秒 15 次的频率重新评估正在被谁指向，因此对话会转到玩家正在看着的对象身上，除非目标设定为 `手动`.

### 选择玩家正在和谁说话

该 **Convai Manager → 玩家正在和谁说话** 部分决定一个处于活动状态的房间当前在对准哪个角色，并且只有当场景中有多个角色可选时才会出现——只有一个角色时根本无需决定。共有三种模式可用： **注视**, **Proximity**，以及 **手动**。请参阅 [选择一个目标模式](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/conversation-targeting/choose-a-targeting-mode.md) 来比较它们，以及 [对话目标定位](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/conversation-targeting.md) 该功能。

该规则不会自行清除目标。当没有任何对象符合条件时——例如玩家看向空白区域——上一个被对话的角色会继续维持对话，而不是变成无人回应。

```mermaid
graph TD
    A["场景加载时有两个或更多处于激活状态的 ConvaiCharacter 组件"] --> B["房间连接；先对初始角色开放，或按场景顺序开放"]
    B --> C["玩家正在和谁说话会以大约每秒 15 次的频率重新评估"]
    C --> D{"是否有其他角色符合条件？"}
    D -- "否" --> C
    D -- "是" --> E["对话转到那个角色"]
    E --> C
```

### 一次只允许一个角色发言

房间在任何时刻都只会有一个角色在回应——切换到另一个角色会停止当前正在回答的角色，哪怕它说到一半、哪怕是在句子中间，所以请参见 [一次只允许一个角色发言](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/conversation-targeting/how-conversation-targeting-works.md#one-character-speaks-at-a-time) 以了解完整规则，以及如何有意让对话一直停留在某一个角色上。

### 为什么每个角色都需要自己的 Character ID

SDK 会按 Character ID 路由所有权、参与者和音频。两个角色共用同一个 ID 时会发生冲突，而不是分别被单独回应；这就是为什么即使某个 Convai 账户拥有多角色访问权限，只要房间里的两个角色使用相同的 ID，它也会拒绝连接，而不是以半工作状态连接。请参见 [角色身份](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/multi-character-sessions/character-identity.md) 以了解确切规则，以及 Character 检视器会报告什么。

### 相关

{% content-ref url="/pages/a6e9c177aa5c598a856889f7e4baf09e8b838a4d" %}
[构建你的第一个多角色会话](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/multi-character-sessions/quick-start.md)
{% endcontent-ref %}

{% content-ref url="/pages/6481618ebe16f2ac14d3eecace53ed97c7f369d1" %}
[角色身份](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/multi-character-sessions/character-identity.md)
{% endcontent-ref %}

{% content-ref url="/pages/d8451a87588c6ea22a959d1a3ecd7ecc09422e8a" %}
[对话目标选择](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/conversation-targeting.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-unity-sdk/features/multi-character-sessions/how-multi-character-sessions-work.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.
