> 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/embodiment/embodiment-presets.md).

# 具身化预设

将多个具身化模块的配置文件打包为一个可复用预设，并应用到角色上，使每个模块的设置一起随之移动。

一个 embodiment 预设会将每个模块——凝视、身体动画、肢体语言、对话流程和情绪——各自一个配置文件打包成一个单一资源，因此一个角色原型的整套个性可以作为一个整体进行交付和更新，而不是分成 5 个独立的配置文件分配。使用本页创建预设并将其应用到角色。

### 前提条件

* 已安装 Convai Unity SDK
* 已经添加了一个包含你想打包的具身模块的角色，每个模块都在 Inspector 中分配了各自的配置文件

### 创建一个预设资源

选择 **Assets > Create > Convai > Embodiment > Preset**。这将创建一个 `ConvaiEmbodimentPreset` 带有一个 **身份** 包含……的部分 **预设 ID** （默认为 `默认值`）以及 **说明**.

**预设 ID** 是其他系统引用此预设所使用的简短标识符——例如一个 `ConvaiEmbodimentPresetLibrary` 条目。将其设置为具体值，例如 `guide-npc` 或 `drill-instructor`，而不要保留默认值。

### 向预设中添加功能

在 **功能**，点击 **添加功能** 以添加一个配置文件槽位。每一行都会提供一个 **功能** 下拉框，其范围限定为项目中存在的具身模块—— **身体动画**, **身体语言**, **对话流程**, **Emotion**，以及 **凝视** ——以及一个 **设置** 字段，该字段只接受该功能所声明的配置文件资源类型，因此你不能分配不匹配的配置文件。

| 功能      | 模块 ID                      | 配置文件类型                          |
| ------- | -------------------------- | ------------------------------- |
| 身体动画    | `convai.body-animation`    | `ConvaiBodyAnimationProfile`    |
| 身体语言    | `convai.body-language`     | `ConvaiBodyLanguageProfile`     |
| 对话流程    | `convai.conversation-flow` | `ConvaiConversationFlowProfile` |
| Emotion | `convai.emotion`           | `ConvaiEmotionProfile`          |
| 凝视      | `convai.gaze`              | `ConvaiGazeProfile`             |

为你希望预设控制的每个模块添加一行。你不需要为每个模块都添加一行——只打包 Gaze 和 Emotion 的预设也是有效的。点击 **删除最后一行** 以删除最近添加的一行，或者点击 **×** 按钮来删除该行。

{% hint style="warning" %}
两行使用相同功能属于配置错误： `HasDuplicateModuleIds(out string message)` 返回 `true`，以及 **检查设置** 部分会将其报告为可修复项。运行时只会使用第一个匹配到的槽位。
{% endhint %}

可通过脚本使用以下方法读取某个槽位的配置文件： `TryGetProfile(string moduleId, out ScriptableObject profile)`，当没有任何槽位匹配给定的模块 ID 时返回 `false` 。

### 将预设应用到角色

添加 **预设** 组件（`Convai/Embodiment/Preset` （在 Add Component 菜单中）到角色根对象，并将预设资源分配给其 **预设** 字段从其他 GameObject 分配一个角色。

当 `Awake`，该组件会查找角色上所有接收具身配置文件的组件，并按模块 ID 将预设中的匹配槽位应用到每一个组件上。没有匹配槽位的模块将保留其在 Inspector 中分配的配置文件，或者不接收配置文件，具体取决于 **保留缺失槽位**:

| `保留缺失槽位`    | 对于没有匹配预设槽位的模块的行为           |
| ----------- | -------------------------- |
| `true` （默认） | 保留该模块在 Inspector 中已分配的配置文件 |
| `false`     | 将该模块的配置文件清空                |

调用 `Apply(ConvaiEmbodimentPreset)` ，以便在运行时切换预设；它会重新扫描角色的接收器，并重新应用每个槽位。

### 使用资源库在运行时切换预设

分配一个 `ConvaiEmbodimentPresetLibrary` 资源（**Assets > Create > Convai > Embodiment > Preset Library**）到 **资源库** 字段，以启用基于 ID 的运行时切换。资源库保存按顺序排列的预设列表，并通过 `Find(id)`查找，且会以不区分大小写的方式匹配每个预设的 `PresetId` 。

{% hint style="info" %}
分配资源库本身不会自动应用任何内容。调用 `ApplyPresetById(string id)` 在 `预设` 组件来在资源库中查找某个预设并将其应用——资源库是一个查找表，而不是一个主动绑定。
{% endhint %}

### 验证预设是否已应用

打开预设资源的 **检查设置** 部分：它会列出诸如重复的功能行、空设置槽位，以及某个功能对应的行但使用此预设的任何角色上都不存在该功能之类的发现项，其中大多数都带有一键修复。没有任何发现项的预设会显示为状态正常。

进入 Play 模式后，检查角色在 Inspector 中每个模块的配置文件字段：它应该显示预设中匹配槽位的配置文件，或者如果 **保留缺失槽位** 未对其进行任何修改，则显示该模块自己的配置文件。若某个槽位的配置文件未能应用， **预设** 组件会记录一条警告，注明模块 ID 和原因——配置文件类型不匹配、缺少接收器，或存在重复槽位。

### 下一步

{% content-ref url="/pages/dddb9a87015e6befbe3c15caf6aa6b2df224fa33" %}
[角色骨架设置](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/embodiment/character-rig-setup.md)
{% endcontent-ref %}

{% content-ref url="/pages/526da9bf1ae481254ffde1d02128e23947af7af5" %}
[具身化编辑器窗口](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/embodiment/embodiment-editor.md)
{% endcontent-ref %}

{% content-ref url="/pages/8eaf58d7e1fc1a2176b0c4b26425f595bc8e8851" %}
[资产所有权与写时复制](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/core-concepts/asset-ownership.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-unity-sdk/embodiment/embodiment-presets.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.
