> 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).

# 动态上下文

动态上下文使 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="/pages/ea4c263729dd22d672acffa78f03bba30e097c52">/pages/ea4c263729dd22d672acffa78f03bba30e097c52</a></td></tr><tr><td><strong>动态上下文快速开始</strong><br>添加 <code>ConvaiDynamicContextRelay</code> 以几步将其连接到 NPC，并验证具备上下文感知的对话。</td><td><a href="/pages/aad74412c9dc416577acffb5b0f1b8be3c9ad61d">/pages/aad74412c9dc416577acffb5b0f1b8be3c9ad61d</a></td></tr><tr><td><strong>Relay 组件参考</strong><br>按字段说明的参考，适用于 <code>ConvaiDynamicContextRelay</code> 的 WebRTC 视频轨道，并且 <code>ConvaiRespondMode</code> 所接受的值。</td><td><a href="/pages/743bcc7de155496cbbf02a52a5577aee99f28aab">/pages/743bcc7de155496cbbf02a52a5577aee99f28aab</a></td></tr><tr><td><strong>连接时的静态上下文</strong><br>为会话期间不会变化的事实配置在连接时仅发送一次的初始动态信息。</td><td><a href="/pages/133014bac66e10680112ab87148615bc885d33d7">/pages/133014bac66e10680112ab87148615bc885d33d7</a></td></tr><tr><td><strong>同步行为与时序</strong><br>如何对 Replace、Append 和 Reset 消息进行批处理与刷新，包括 <code>DynamicContextBatchDelaySeconds</code> 窗口。</td><td><a href="/pages/bb1aef3496a2be08987c770aa7b8072e7d8c5cd6">/pages/bb1aef3496a2be08987c770aa7b8072e7d8c5cd6</a></td></tr><tr><td><strong>动态上下文脚本 API</strong><br>关于 <code>ConvaiCharacter.DynamicContext</code>的完整 API 参考，包括 <code>ConvaiRespondMode</code> 从反应模式的迁移。</td><td><a href="/pages/5c3f9bcc544ac6f441fe54139ac1c670eeb5c958">/pages/5c3f9bcc544ac6f441fe54139ac1c670eeb5c958</a></td></tr><tr><td><strong>动态上下文使用示例</strong><br>涵盖安全演练、入职引导、导览以及已同步世界对象跟踪的端到端场景。</td><td><a href="/pages/493c8451db0d99cc31b81e26c17158c645622f0e">/pages/493c8451db0d99cc31b81e26c17158c645622f0e</a></td></tr><tr><td><strong>排查动态上下文问题</strong><br>关于 Relay 和跟踪器流程的排查清单、症状表以及 Console 日志参考。</td><td><a href="/pages/531d80b1af7cb4aba63c4979e0a4c0f8e029bc95">/pages/531d80b1af7cb4aba63c4979e0a4c0f8e029bc95</a></td></tr></tbody></table>

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

A `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.
