> 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** 组件直接体现了这一点。它的 **Scene Setup** 部分会自动检测场景中的每一个 `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["Who The Player Talks To 约每秒重新评估 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
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=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
