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