> 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-unreal-engine-plugin/features/scene-metadata/scene-metadata-usage-examples.md).

# 场景元数据使用示例

在 Unreal Engine 中为训练模拟、工业演练、军事基地和运行时环境更新提供完整的场景元数据设置。

以下示例涵盖了用于培训模拟和交互式体验的实用配置。每个示例都会介绍场景、所需的 Details 面板或 Blueprint 配置，以及预期的运行时效果。请从与当前复杂度相符的示例开始。

### 示例 1：医疗培训模拟 — 解剖实验室

**场景：** 一个外科培训模拟场景：医疗指导 NPC 带领学员参观解剖实验室。角色必须识别并描述房间内的实体模型和设备——学员会提出诸如 `"What is this organ?"` 或 `"Where is the aorta?"`

#### 配置

此示例无需编写 Blueprint 脚本。为关卡中的每个解剖模型和设备 `UConvaiObjectComponent` 添加到对应的 `Actor` 上。在 **Details** 面板中，为 `Name` 和 `Description` 字段设置 `ObjectEntry`:

| 名称                | 说明                                                                                                               |
| ----------------- | ---------------------------------------------------------------------------------------------------------------- |
| `HeartModel`      | `"Life-size anatomical heart model on the center examination table. Shows all four chambers and major vessels."` |
| `LiverModel`      | `"Adult liver model mounted on the left side of the display rack. Hepatic veins are color-coded."`               |
| `SurgicalScalpel` | `"Standard surgical scalpel resting on the instrument tray. Handle is blue."`                                    |
| `Stethoscope`     | `"Stethoscope hanging on the hook next to the examination table."`                                               |

指导角色会在会话开始时接收所有描述，因此学员关于房间的问题可以结合场景中实际配置的条目来回答。

{% hint style="success" %}
学员提问： `"What models are available for study?"` 合适的回答可以引用场景元数据中 `HeartModel` 和 `LiverModel` 的描述。
{% endhint %}

### 示例 2：工业安全演练 — 基于阶段的对象感知

**场景：** 一个包含多个演练阶段的安全培训模块。每个阶段都会引入不同的危险因素和设备。如果某阶段的道具是在会话开始后才加入的，则运行时更新对象信息会很有用。

#### 配置

在每个阶段加载时，在聊天机器人组件上调用 `ClearObjects` 和 `AddObject` 。在最后一次调用时传入 `bFlushImmediately = true` ，将所有待处理更新合并为一条消息。

```cpp
// C++ — 切换到新的演练阶段时，在聊天机器人组件上调用
void ASafetyDrillManager::LoadPhase(int32 PhaseIndex)
{
    // 移除上一阶段的所有对象
    ChatbotComponent->ClearObjects(false);

    // 仅添加当前阶段的属性
    const TArray<FConvaiObjectEntry>& PhaseEntries = PhaseProps[PhaseIndex];
    for (int32 i = 0; i < PhaseEntries.Num(); ++i)
    {
        bool bFlush = (i == PhaseEntries.Num() - 1); // 在最后一个条目上刷新
        ChatbotComponent->AddObject(PhaseEntries[i], bFlush);
    }
}
```

在蓝图中，依次连接 **清除对象** （立即刷新： `false`），然后连接一个或多个 **添加对象** 节点，并将 **立即刷新** 设为 `true` （仅限最后一个节点）。

此模式会通过运行时环境更新路径发送新的阶段属性。如果阶段对象已包含在 `action_config` 中，并且是在 `/connect`时添加的，请在阶段开始前重新连接，以便下一次会话从正确的对象集合开始。

### 示例 3：军事模拟——包含实时闸门状态的前进作战基地

**场景：** 一个军事训练模拟场景：战术军官熟悉前进作战基地的布局。安全闸门具有实时访问状态，闸门状态变化应作为受跟踪的状态发送给 Convai。

#### 配置

为每个建筑和安全闸门 `UConvaiObjectComponent` 添加到各自的 `Actor`上。对于静态建筑，只需要 `Name` 和 `Description` 。对于安全闸门，还要添加一个受跟踪的属性：

1. 展开 **受跟踪的属性** 并点击 **+**.
2. 点击 **绑定** （位于 **属性路径** 旁边），然后从闸门 `bIsOpen` 中选择 `Actor`.
3. 将 **`Description`** 设为 `"Whether the security gate is currently open."`.
4. 设置 **`ShouldRespond`** 到 `Always`.

| 名称            | 说明                                                                                                          |
| ------------- | ----------------------------------------------------------------------------------------------------------- |
| `CommandPost` | `"Main command post at grid reference Alpha-7. Houses mission briefing room and communications equipment."` |
| `Armoury`     | `"Armory building on the eastern perimeter. Access is restricted to authorized personnel."`                 |
| `NorthGate`   | `"Northern security gate. Controls vehicle and personnel access to the forward operating base."`            |

当 `bIsOpen` 属性在 `NorthGate` `Actor` 运行时发生变化时，插件会在跟踪属性轮询中检测到此变化，并安排动态上下文更新，将 `ShouldRespond` 设置为 `Always`.

{% hint style="success" %}
玩家打开北门。下一次跟踪属性更新会发送新的 `bIsOpen` 值，并请求响应。
{% endhint %}

### 示例 4：跟踪带有各值描述的枚举

**场景：** 一款企业入职模拟中，服务器机房终端具有一个 `ETerminalState` `UPROPERTY` ，其状态会在 `Offline`, `Standby`和 `Active`之间循环切换。指南应以通俗易懂的语言说明每个枚举值的含义。

#### 配置

1. 将 `TerminalState` 绑定为跟踪属性。
2. 将 **`Description`** 设置为 `"The current operating state of the server terminal."`.
3. 展开 **状态值描述** （位于详细信息面板的 **高级** 下方），并添加三行：

| 值           | 说明                                   |
| ----------- | ------------------------------------ |
| `"Offline"` | `"Terminal has no power."`           |
| `"Standby"` | `"Terminal is powered but idle."`    |
| `"Active"`  | `"Terminal is processing requests."` |

状态值描述会合并到对象的会话启动描述中，而运行时发生变化时则会发送当前的原始枚举值。这样一来，Convai 就能同时获得来自 `action_config` 以及动态上下文更新中的当前状态。

### 示例 5：在会话开始时动态填充环境

**场景：** 一个程序化生成的训练设施，每次会话的房间布局都会变化。AI 教员对物体的感知必须通过运行时世界查询构建，而不能依赖“细节”面板中的固定列表。

#### 配置

在 `GatherEnvironmentExtras` UConvaiChatbotComponent `的 Blueprint 子类中重写`。此事件会在 `StartSession()` 内部运行一次，且在 `/connect` 握手之前运行，因此此处添加的每个条目都会包含在冻结的 `action_config` 快照中。

```
// Blueprint 伪代码 — 在 UConvaiChatbotComponent 子类的事件图中重写
// 事件：收集环境附加项 (OutExtraActions, OutExtraObjects, OutExtraCharacters)

For each Actor in GetAllActorsWithComponent(UConvaiObjectComponent):
    Entry = Create FConvaiObjectEntry(
        Name        = Actor.ConvaiObjectComponent.ObjectEntry.Name,
        Description = Actor.ConvaiObjectComponent.ObjectEntry.Description,
        Ref         = Actor
    )
    OutExtraObjects.Add(Entry)
```

`OutExtraObjects` 会与已配置的 `EnvironmentData.Objects` 列表合并，然后再发送 `action_config` 。合并后的环境中，名称相同的条目会替换较早添加的条目。

### 示例 6：为固定背景道具禁用移动感知

**场景：** 某博物馆导览模拟使用一幅大型彩绘壁画，覆盖每个展厅的整面后墙。壁画在对话中有助于提供语境，但它从不移动，因此没必要在每个轮询周期都花费一次轮询来采样其变换信息。

#### 配置

将 `UConvaiObjectComponent` 添加到壁画的 `Actor` 上，并设置：

* **`Name`**: `"HistoryMural"`
* **`Description`**: `"一幅描绘该机构历史的大型彩绘壁画，覆盖每个展厅的整面后墙。"`
* **启用移动感知** (`bEnableMovementAwareness`（位于 `MovementAwareness`下）：禁用。

导览仍可通过空间感知获取壁画的身份、位置和可达性 — 请参阅 [空间感知](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/spatial-awareness.md) — 但插件不再在每次轮询时采样壁画的变换信息，也不会为其生成移动描述。任何不会移动的大型固定道具都可以采用此模式。

### 后续步骤

{% content-ref url="/pages/35be910ed18e7f78411fd4d732770d70307e1434" %}
[排查场景元数据问题](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/scene-metadata/troubleshoot-scene-metadata.md)
{% endcontent-ref %}

{% content-ref url="/pages/5b34043c604b8f8fd8088c66f01ea7887fcd8846" %}
[场景元数据组件参考](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/scene-metadata/scene-metadata-component-reference.md)
{% endcontent-ref %}

{% content-ref url="/pages/a6fd7e3b5ee94be300d9c248743b197b93cc0c96" %}
[场景元数据的工作原理](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/scene-metadata/how-scene-metadata-works.md)
{% endcontent-ref %}

{% content-ref url="/pages/4a8ee50a93a78b9b86484cb79897f6d0d6bde187" %}
[运行时管理环境](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/scene-metadata/managing-the-environment-at-runtime.md)
{% endcontent-ref %}


---

# 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-unreal-engine-plugin/features/scene-metadata/scene-metadata-usage-examples.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.
