> 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/character-identity.md).

# 角色身份

为共享同一 Convai 房间的角色分配 Character ID 的参考，以及检测两个角色使用同一 ID 的检查机制。

每个 `ConvaiCharacter` 房间中的对象都需要拥有自己的 Character ID。两个角色不能共用同一个 ID，SDK 会在编辑场景时和房间连接时分别检查这一点。

### 为什么不能共用 ID

SDK 根据 Character ID 路由所有权、参与者和音频。两个角色持有相同的 ID，并不会各自获得独立的路由——第二个角色会与第一个发生冲突，房间会通过最先注册的角色响应这两个角色，而不是将它们分开处理。

复制一个正常工作的角色，是在场景中创建第二个角色的常见方式，而副本会沿用原角色的 Character ID。下面的两项检查正是为了应对这种情况。

### 编辑模式下角色检查器中的警告

选择一个 `ConvaiCharacter` 如果它与已加载场景中的另一个角色共用 Character ID，其检查器中会显示一个标题为 **另一个角色使用了此 Character ID**:

```
的错误框。已加载场景中的“<other character>”使用了相同的 ID。SDK 根据 Character ID 路由所有权、参与者
和音频，因此两个角色共用一个 ID 会导致冲突，而不是各自获得独立路由——
房间会将它们都路由到最先注册的角色。请从
Convai 控制面板为此角色分配一个专属 ID。
```

此消息会列出所有与该角色共用 ID 的其他角色，而不只是找到的第一个角色。无论是否启用了多角色会话，都会执行此检查——任何场景中出现重复 ID 都是不正确的，因为无论房间包含多少角色，注册表都以该 ID 作为路由键。

{% hint style="info" %}
`Convai.ValidateSetup` 也会将同一冲突报告为错误，因此持续集成任务或编辑器脚本无需打开检查器即可发现该问题。
{% endhint %}

### 连接房间时拒绝连接

如果房间中处于活动状态且已启用的角色里有两个使用相同的 Character ID，房间将拒绝连接。 `ConvaiOperationException` 会包含以下消息：

```
“<first character>”和“<second character>”都使用了 Character ID <id>。同一个房间中的两个角色
不能共用一个 ID——SDK 根据该 ID 路由所有权、参与者和音频，因此它们会发生冲突，
而无法分别获得响应。请从 Convai
控制面板为每个角色分配各自的 Character ID。
```

无论是连接时提交完整角色阵容，还是房间已启动后再添加单个角色，这两种将角色加入房间名单的途径都会执行此检查。无论哪种情况，房间都会拒绝连接或拒绝添加角色，而不会在两个角色发生冲突的情况下继续运行。

### Character ID 格式

&#x20;**Character ID**  字段位于 `ConvaiCharacter` 上，其验证独立于重复 ID 检查。如果值无效，检查器中会显示以下某条消息：

| 条件      | 消息                                                                                                                                                                              |
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 字段为空    | `Character ID is required. Copy it from your character's page on the Convai dashboard.`                                                                                         |
| 首尾包含空格  | `Character ID has a space before or after it. Delete the extra spaces.`                                                                                                         |
| 长度错误    | `Character ID should be 36 characters, and this one is <length>. Copy the whole ID from the Convai dashboard.`                                                                  |
| 不是 GUID | `Character ID is not in the expected form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. Copy it again from the Convai dashboard — it is easy to pick up a character's name by mistake.` |

比较重复 ID 时会忽略大小写和首尾空格，因此 `AB12…` 和 `ab12…` 会被视为同一个 ID。没有 ID 的角色会被重复 ID 检查跳过，并由上面的格式检查报告。

### 相关内容

{% content-ref url="/pages/1de47e20d64086de6ea2148c4871a665eec92182" %}
[多角色会话工作原理](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)
{% endcontent-ref %}

{% content-ref url="/pages/a6e9c177aa5c598a856889f7e4baf09e8b838a4d" %}
[构建你的第一个多角色会话](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/multi-character-sessions/quick-start.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/character-identity.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.
