> 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/scene-metadata/troubleshooting-and-diagnostics.md).

# 排查场景元数据问题

修复场景元数据问题，包括空负载、缺少集合日志、依赖注入失败，以及 AI 角色忽略场景物体。

大多数场景元数据问题都属于以下三类之一：载荷从未发送、载荷已发送但对象被排除，或者描述过于含糊，AI 无法有效使用。

### 初步排查

启用 **日志统计** 开启 `ConvaiSceneMetadataCollector` （默认开启），然后进入播放模式后检查控制台。成功收集时会记录类似以下的调试日志：

```
[ConvaiSceneMetadataCollector] Collected N metadata objects in X.XXXXs. Registry stats: Y total, Z valid, W invalid
```

如果没有出现此日志，则表示收集未运行。如果出现的日志显示 `Collected 0 metadata objects`，负载为空。

调用 `ValidateAllMetadata()` 从临时调试脚本中调用，以获取每个对象的详细信息：

```csharp
void Start()
{
    FindObjectOfType<ConvaiSceneMetadataCollector>()?.ValidateAllMetadata();
}
```

### 症状参考

| 症状                                       | 可能原因                                                 | 解决方法                                                   | 验证                                                                                      |
| ---------------------------------------- | ---------------------------------------------------- | ------------------------------------------------------ | --------------------------------------------------------------------------------------- |
| 控制台中没有收集日志                               | `Collect On Start` 已禁用，且未手动调用                        | 启用 **启动时收集** 或调用 `CollectAndSendSceneMetadata()` 会话连接后 | 重新进入播放模式，并确认 `[ConvaiSceneMetadataCollector] Collected N metadata objects...` 条目出现在控制台中 |
| `"Dependencies not injected"` 错误         | `ConvaiSceneMetadataCollector` 场景中没有 `ConvaiManager` | 添加 `ConvaiManager` 到场景中；收集器会自动解析它                      | 进入播放模式时不再出现此错误                                                                          |
| `Collected 0 metadata objects` 日志中的      | 所有对象均已从有效负载中排除                                       | 请参阅 [空载荷](#empty-payload) 以下                           | `GetMetadataCount()` 返回一个大于 `0`                                                         |
| 编辑器中的对象名称验证警告                            | 名称为空或超过 50 个字符                                       | 设置一个非空且少于 50 个字符的名称                                    | 控制台警告会在下一次 `OnValidate` 调用后清除（取消选择并重新选择该 GameObject）                                    |
| 已确认发送，但 AI 忽略了对象                         | 描述缺失或过于模糊                                            | 请参阅 [改进描述](#improving-descriptions) 下文                 | 向角色提出一个必须依赖重写后细节才能回答的问题，并确认回复中包含该细节                                                     |
| 对象存在于注册表中，但未包含在负载中                       | `Include In Metadata` 未勾选，或组件已禁用                     | 在 Inspector 中检查此字段；如有需要，重新启用该组件                        | 该对象出现在 `GetValidMetadata()` 或下一次 `ValidateAllMetadata()` 检查中                            |
| `Is Registered` 显示 `false` 在 Inspector 中 | 组件已添加，但 `OnEnable` 尚未触发                              | 确保 GameObject 和组件均已启用                                  | `Is Registered` 显示 `true` 在播放模式下                                                        |
| 跟踪的属性在角色上始终不会更新                          | **源成员名称** 与……上的属性、字段或无参数方法不匹配 **源组件**                | 修正成员名称；名称不匹配会静默失败，条目会保留其最后已知值，而不会报错                    | 角色的回应会在一个 0.25 秒的轮询间隔内反映新值                                                              |
| 静态元数据编辑不会同步到已连接的角色                       | 会话未连接，或角色当前不在对话中                                     | 只有在角色已连接且正在对话时，实时重新同步才会执行刷新——请重新连接，或等待下次连接时发送          | 重新连接后，询问角色有关已编辑对象的问题，并确认使用了更新后的文本                                                       |

### 空载荷

何时 `Collected 0 metadata objects` 出现时，请按顺序检查以下事项：

**1. 是否有任何 `ConvaiObjectMetadata` 组件已启用？** 已禁用的组件不会注册。选择目标 GameObject，并在 Inspector 中检查组件开关。

**2. 是否已勾选 `Include In Metadata` ？** 此字段为 `true` 默认情况下如此，但运行时代码可能已将其设置为 `false`。检查 `ConvaiMetadataRegistry.GetStatistics()` 以查看被排除对象的数量。

**3.  `Object Name` 是否非空？** 名称为空的对象会通过 `IsRegistered` 检查，但无法通过 `IsValid` 检查，因此不会发送。调用 `ValidateAllMetadata()` 来找出这些对象。

```csharp
// 调试统计信息明细
var stats = ConvaiMetadataRegistry.GetStatistics();
foreach (var kv in stats)
    Debug.Log($"{kv.Key}: {kv.Value}");
```

### 改进描述

AI 会将 `Object Description` 字段内容作为事实依据。描述含糊，回复也会含糊。

| 避免使用      | 改用                                    |
| --------- | ------------------------------------- |
| `"一个灭火器"` | `"安装在南墙上、与视线齐平的红色 ABC 干粉灭火器，位于紧急出口旁"` |
| `"桌子"`    | `"实验室中央的钢制检查台，高 90 厘米，配有可调节腿托"`       |
| `"门"`     | `"带黄色警示条的厚重钢制压力门，通往冷却室"`              |

指南：

* 说明物体相对于地标或房间特征的位置
* 提供视觉识别信息——颜色、尺寸、材质
* 在适用时说明功能或用途
* 控制在 200 个字符以内

### 决策树

当 AI 未对场景中的物体作出响应时，请使用此决策树：

```
IsReadyToSendMetadata() 是否返回 true？
├── 否 → 场景中是否有 ConvaiManager？房间是否已连接？
│         修复方法：添加 ConvaiManager，并确保会话进入 Connected 状态
└── 是 → GetMetadataCount() 是否大于 0？
          ├── 否 → 运行 ValidateAllMetadata()。检查 Include In Metadata 和 Object Name 字段
          └── 是 → 描述是否客观且具体？
                    ├── 否 → 重写描述，补充位置和关键属性
                    └── 是 → 检查 Convai 控制面板中的角色设置
```

### 后续步骤

{% content-ref url="/pages/553ff838d38639ef80a27f8380dc466768470562" %}
[场景元数据脚本 API](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/scene-metadata/scripting-api-reference.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/scene-metadata/troubleshooting-and-diagnostics.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.
