> 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/narrative-design/fetching-narrative-data.md).

# 获取叙事数据

在运行时使用 Convai Fetch Narrative Sections 和 Convai Fetch Narrative Triggers 查询角色的叙事区段和触发器。

Convai Unreal Engine 插件在 **Convai|REST API** 下提供两个异步蓝图节点，用于从 Convai 获取角色的叙事片段和触发器。可使用这些节点在调用触发器前验证其名称、填充动态 UI，或在加载画面期间预缓存叙事数据。

这些节点是可选的。正常的故事推进流程是使用 **Invoke Narrative Design Trigger** 在 `UConvaiChatbotComponent`上调用，而不是先获取再调用。

### 前提条件

* Convai Unreal Engine 插件已安装，且已配置 API 密钥。请参阅 [配置 API 密钥](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/getting-started/configure-your-api-key.md).
* 有效的 `CharacterId` ，与目标 `CharacterID` 相匹配 `UConvaiChatbotComponent`.
* 执行获取节点时能够访问网络。获取节点会向 Convai 发起 HTTPS POST 请求。

### 获取叙事片段

**Convai Fetch Narrative Sections** 是一个异步潜伏式蓝图节点，由 `UFetchNarrativeSectionsProxy`实现。它会向 `character/narrative/list-sections` 发送 POST 请求，并返回在控制面板中为该角色配置的片段。

| 引脚                   | 方向     | 类型                          | 说明                                                           |
| -------------------- | ------ | --------------------------- | ------------------------------------------------------------ |
| `CharacterId`        | 输入     | `FString`                   | 要查询的角色 ID。必须与目标 `CharacterID` 相匹配 `UConvaiChatbotComponent`. |
| `On Success`         | 输出（执行） | —                           | HTTP 请求成功且响应已解析为 `FNarrativeSection` 条目时触发。                  |
| `On Failure`         | 输出（执行） | —                           | 激活验证失败、响应指针无效，或 HTTP 响应不在 `2xx` 范围内时触发。                      |
| `Narrative Sections` | 输出     | `TArray<FNarrativeSection>` | 成功时返回的片段。失败时为空。                                              |

**要在蓝图中添加此节点：**

1. 右键单击事件图表，然后搜索 `Fetch Narrative Sections`.
2. 选择 **Convai Fetch Narrative Sections** 下的 **Convai|REST API**.
3. 将 `CharacterId` 输入设为与所用 `UConvaiChatbotComponent` 相同的值。
4. 将节点连接到 **On Success** 和 **On Failure** 执行引脚。

### 获取叙事触发器

**Convai 获取叙事触发器** 是一个异步潜伏式 Blueprint 节点，由 `UFetchNarrativeTriggersProxy`实现。它会向 `character/narrative/list-triggers` 发送 POST 请求，并返回角色叙事图中配置的触发器。

| 引脚            | 方向     | 类型                          | 说明                                         |
| ------------- | ------ | --------------------------- | ------------------------------------------ |
| `CharacterId` | 输入     | `FString`                   | 要查询的角色 ID。                                 |
| `On Success`  | 输出（执行） | —                           | HTTP 请求成功且响应解析为 `FNarrativeTrigger` 条目后触发。 |
| `On Failure`  | 输出（执行） | —                           | 激活验证失败、响应指针无效，或 HTTP 响应不在 `2xx` 范围内时触发。    |
| `叙事触发器`       | 输出     | `TArray<FNarrativeTrigger>` | 成功时返回的触发器。失败时为空。                           |

结果中的每个 `FNarrativeTrigger` 都提供以下字段： `trigger_name`, `trigger_id`, `trigger_message`和 `destination_section` ，这些字段均为 `BlueprintReadOnly` 。其中 `trigger_name` 字段可用于调用 **调用叙事设计触发器**.

### 何时调用获取节点

应在加载时调用获取节点，而不是在游戏过程中反复调用：

* **Begin Play** ——在调用任何触发器之前获取数据，确保游戏开始时数据已就绪。
* **加载画面** ——在玩家无法与角色互动时，与其他加载工作并行获取数据。
* **编辑器工具 Blueprint** ——无需打开 Convai 控制面板，即可在 Unreal Editor 中检查角色的叙事图。

{% hint style="warning" %}
每次执行获取节点时，都会向 Convai 发送 HTTPS 请求。不要在 Tick 时或响应重复发生的游戏事件时调用它们。将结果缓存到 Blueprint 变量中并重复使用。
{% endhint %}

### 处理结果

在 **成功时** 引脚上， **Convai 获取叙事触发器**遍历 `Narrative Triggers` 数组，并将每个 `trigger_name` 提取到 `TSet<FString>` 或 Map 变量中。调用 **调用叙事设计触发器**之前，请检查目标名称是否在集合中。

在 **成功时** 引脚上， **Convai 获取叙事章节**，遍历 `Narrative Sections` 并使用每个 `section_id` 和 `section_name` 来填充下拉菜单或调试覆盖层。

如需完整的触发器验证步骤，请参阅 [叙事设计用法示例](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/narrative-design/narrative-design-usage-examples.md#fetch-triggers-to-validate-names-before-invoking).

### 验证获取操作

在“在编辑器中运行”中运行获取节点后：

1. 确认 **On Success** 执行引脚触发（而不是 **On Failure**).
2. 检查 `Narrative Sections` 或 `Narrative Triggers` ——数组中应包含所查询角色对应的条目。
3. 如果 **On Failure** 触发，请查看 **输出日志** 中的 `ConvaiNarrativeHTTP` 消息。请参阅 [排查叙事设计问题](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/narrative-design/troubleshoot-narrative-design.md).

{% hint style="info" %}
如果 HTTP 请求成功，但响应数组无法解析为叙事结构体，获取代理可能会直接返回，而不触发 **On Success** 或 **On Failure**。如果潜在节点似乎卡住了，请查看 **输出日志** 中的 `ConvaiNarrativeHTTP` ，并确认控制面板中已为该角色配置叙事数据后重试。
{% endhint %}

### 后续步骤

{% content-ref url="/pages/ff19704aac20f7d6e4bf5c3214636ccbe4248151" %}
[叙事触发器](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/narrative-design/narrative-triggers.md)
{% endcontent-ref %}

{% content-ref url="/pages/579f95b35d1b473357f37588e6fc915a03231497" %}
[叙事设计 Blueprint 参考](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/narrative-design/narrative-design-blueprint-reference.md)
{% endcontent-ref %}

{% content-ref url="/pages/609986e3902c22d2027f232e5ffaaa507011c8a0" %}
[排查叙事设计问题](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/narrative-design/troubleshoot-narrative-design.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/narrative-design/fetching-narrative-data.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.
