> 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/dynamic-context.md).

# 动态上下文

查找通过动态上下文中继、脚本 API 和同步世界对象属性向 Convai 角色发送实时场景状态的指南。

动态上下文让 Convai 角色能够实时感知 Unity 场景中发生的事情。角色可以提及受训者当前所在的工位、最近拾取的物品或触发的警报，并在事情发生时将这些信息融入对话。两种入口都会写入同一跟踪状态，并产生完全相同的网络行为： `ConvaiDynamicContextRelay` 用于事件驱动绑定的 Inspector 组件，以及 `DynamicContext` 属性，该属性位于 `ConvaiCharacter` 上，适用于代码驱动的系统。

<table data-view="cards"><thead><tr><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>动态上下文的工作原理</strong><br>了解跟踪状态和事件模型、批处理行为，以及确认结果如何传递到你的代码中。</td><td><a href="https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/dynamic-context/how-dynamic-context-works.md">动态上下文的工作原理</a></td></tr><tr><td><strong>动态上下文快速入门</strong><br>将 <code>ConvaiDynamicContextRelay</code> 添加到 NPC，并通过几个步骤验证上下文感知对话。</td><td><a href="https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/dynamic-context/dynamic-context-quick-start.md">动态上下文快速开始</a></td></tr><tr><td><strong>Relay 组件参考</strong><br>关于 <code>ConvaiDynamicContextRelay</code> 和它接受的 <code>ConvaiRespondMode</code> 值的逐字段参考。</td><td><a href="https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/dynamic-context/relay-component-reference.md">中继组件参考</a></td></tr><tr><td><strong>连接时的静态上下文</strong><br>配置连接时发送一次的初始动态信息，用于记录会话期间不会变化的事实。</td><td><a href="https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/dynamic-context/static-context-at-connection-time.md">连接时的静态上下文</a></td></tr><tr><td><strong>同步行为与时序</strong><br>Replace、Append 和 Reset 消息的批处理与刷新方式，包括 <code>DynamicContextBatchDelaySeconds</code> 时间窗口。</td><td><a href="https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/dynamic-context/sync-behavior-and-timing.md">同步行为与时序</a></td></tr><tr><td><strong>动态上下文脚本 API</strong><br>关于 <code>ConvaiCharacter.DynamicContext</code>的完整 API 参考，包括所有方法和 <code>ConvaiRespondMode</code> 枚举。</td><td><a href="https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/dynamic-context/dynamic-context-scripting-api.md">动态上下文脚本 API</a></td></tr><tr><td><strong>动态上下文用法示例</strong><br>端到端场景示例，涵盖安全演练、入职引导、导览，以及同步跟踪世界对象。</td><td><a href="https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/dynamic-context/dynamic-context-usage-examples.md">动态上下文使用示例</a></td></tr><tr><td><strong>排查动态上下文问题</strong><br>Relay 和跟踪器流程的调查清单、症状表和 Console 日志参考。</td><td><a href="https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/dynamic-context/troubleshoot-dynamic-context.md">排查动态上下文问题</a></td></tr></tbody></table>

### 同步的世界对象上下文

一个 `ConvaiObjectMetadata` 组件可以公开场景对象上受跟踪的属性。每个受跟踪属性都会映射到一个动态上下文状态，并自动发送给所有已连接的角色，无需在代码中显式调用 `SetState` 。有关如何注册对象和配置受跟踪属性，请参阅 [场景元数据](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/scene-metadata.md) 。

### 后续步骤

先阅读 [动态上下文快速入门](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/dynamic-context/dynamic-context-quick-start.md) ，开始使用上下文感知对话。然后阅读 [动态上下文的工作原理](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/dynamic-context/how-dynamic-context-works.md) ，了解跟踪状态和事件模型，再继续阅读参考页面。


---

# 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/dynamic-context.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.
