> 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="/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="/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="/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="/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="/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>完整 API 参考，适用于 <code>ConvaiCharacter.DynamicContext</code>，包括每个方法和 <code>ConvaiRespondMode</code> 枚举。</td><td><a href="/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="/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 和 Tracker 流程的故障排查清单、症状表以及 Console 日志参考。</td><td><a href="/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` 调用。请参见 [场景元数据](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/scene-metadata.md) 了解如何注册对象并配置已跟踪属性。

### 下一步

先从 [动态上下文快速入门](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/dynamic-context/dynamic-context-quick-start.md) 以让具备上下文感知的对话运行起来。然后阅读 [动态上下文如何工作](/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.
