> 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/unreal-engine/guides/actions-guide/stage-3-custom-actions-with-single-parameter.md).

# 阶段 3：带单个参数的自定义动作

动作可以带有参数，例如： `拾取` 是一个期望接收一个将被拾取的对象的动作，在本指南中，我们将了解如何解析这些参数，以及诸如文本之类的其他类型参数。

### 引用对象或角色

在你的 AI 角色中引用对象或角色非常重要，原因有两个：首先，它会知道该对象/角色的存在；其次，当与它们相关的动作被触发时，你将能够获取这些对象或角色的引用，例如 `移动到 - 拾取 - 跟随` 都会始终与对象或角色一起触发

引用对象需要你将该对象添加到 [环境](/api-docs/zh/cha-jian-yu-ji-cheng/unreal-engine/blueprints-reference/convai-environment.md) 位于……中的对象 [ConvaiChatbot](/api-docs/zh/cha-jian-yu-ji-cheng/unreal-engine/blueprints-reference/convai-chatbot.md) 组件中。这样做有两种方式：

1. 第一种方法是在场景中选择角色，然后在细节面板下，将引用添加到 `Convai Info`下的 Objects 数组中，这种方法要求你继承自 `ConvaiBaseCharacter` 蓝图。<br>

   <div align="center"><figure><img src="/files/276586d8a48f46ee8b6bf3ef6dd3551f2a8481dd" alt="" width="405"><figcaption></figcaption></figure></div>
2. 在 `开始游戏` 事件中，在角色蓝图上遍历你希望角色了解的所有对象，然后将其添加到环境对象中。在下面的蓝图中，我们给想要添加到环境中的对象添加了标签，这样就能更方便地在开始游戏时获取它们，然后我们分别使用第二和第三个标签作为名称和描述。

   <figure><img src="/files/56967b5127b3f973547ae23886aa1b628712a7c1" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}

* 可以在运行时添加、编辑或移除对象。
* 使用 `Add Object` 用于对象的函数和 `添加角色` 用于角色。
* 如果你使用 `CovnaiBaseCharacter 作为父类，则会处理环境中玩家和其他角色的添加。`
  {% endhint %}

### 解析对象和角色类型

当你成功将对象和角色添加到环境后，让我们通过一个快速场景来看看如何处理响应：

* 创建一个名为 `看向` 的动作，该动作会强制 AI 角色看向某个特定对象或角色。<br>

  <figure><img src="/files/f8d6d8fe9845d5e15521c8e989ab4373e34ecb09" alt=""><figcaption></figcaption></figure>
* 在角色蓝图中创建一个同名事件，并添加一个类型为 [Convai Result Action](/api-docs/zh/cha-jian-yu-ji-cheng/unreal-engine/blueprints-reference/convai-result-action.md)的输入参数，这将包含该动作所需的参数，在我们的例子中就是要看向的对象/角色。<br>

  <figure><img src="/files/d356fa81bc42aee9a627f79414690098618e0741" alt=""><figcaption></figcaption></figure>
* 现在让我们按如下方式完成实现，我们将拆分 `动作参数` 结构，然后设置 `相关对象或角色` 为 `主角`，请注意，这只是一个让 AI 角色看向所引用对象或角色的快速技巧。<br>

  <figure><img src="/files/ca6348115a160eec963212b35e84d6bf746756a2" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}

* 拆分 `相关对象或角色` 结构，以获取有关该对象或角色的更多详细信息，例如其引用、名称和描述。<br>

  <figure><img src="/files/2902f0a8eab098d8479fa2c6da051d7613ec0091" alt=""><figcaption></figcaption></figure>
* 如果你没有为该对象添加引用，你将得到一个无效引用，但仍然可以得到名称和描述。
  {% endhint %}

### 解析其他参数类型

待续..


---

# 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/unreal-engine/guides/actions-guide/stage-3-custom-actions-with-single-parameter.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.
