> 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 角色能够实时感知场景中正在发生的事情。角色可以引用实时状态——学员当前的位置、已收集的装备、已触发的危险，或检查点状态——并将这些信息自然地融入对话中。更新通过两个入口传入： `ConvaiDynamicContextCommand` Inspector 组件（无需代码）以及 `IConvaiDynamicContext` 上的脚本接口 `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>在 5 个步骤中将命令组件添加到 NPC，并验证上下文感知对话。</td><td><a href="/pages/aad74412c9dc416577acffb5b0f1b8be3c9ad61d">/pages/aad74412c9dc416577acffb5b0f1b8be3c9ad61d</a></td></tr><tr><td><strong>命令组件参考</strong><br>涵盖全部六种命令类型、反应模式和验证警告的逐字段参考。</td><td><a href="/pages/fe2e3da29009b41a36bf622ae1efd7921e09aab7">/pages/fe2e3da29009b41a36bf622ae1efd7921e09aab7</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 消息的传输方式与时机。</td><td><a href="/pages/bb1aef3496a2be08987c770aa7b8072e7d8c5cd6">/pages/bb1aef3496a2be08987c770aa7b8072e7d8c5cd6</a></td></tr><tr><td><strong>动态上下文脚本 API</strong><br>完整 API 参考： <code>IConvaiDynamicContext</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>针对常见问题的排查清单、症状表、决策树和 Console 日志参考。</td><td><a href="/pages/531d80b1af7cb4aba63c4979e0a4c0f8e029bc95">/pages/531d80b1af7cb4aba63c4979e0a4c0f8e029bc95</a></td></tr></tbody></table>

### 下一步

从以下开始 [动态上下文快速入门](/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:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/dynamic-context.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
