> 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).

# 具身化预设

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

一个具身化预设将每个模块的一个配置文件——Gaze、Body Animation、Body Language、Conversation Flow 和 Emotion——捆绑到一个单一资源中，因此某个角色原型的完整个性会作为一个整体进行交付和更新，而不是分成五个独立的配置文件分配。请使用此页面来创建一个预设并将其应用到角色。

### 前提条件

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

### 创建预设资源

选择 **Assets > Create > Convai > 具身化 > 预设**。这将创建一个 `ConvaiEmbodimentPreset` 带有一个 **标识** 包含 **预设 ID** （默认值为 `default`）和 **描述**.

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

### 向预设添加功能

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

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

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

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

在脚本中通过以下方式读取某个槽位的配置文件： `TryGetProfile(string moduleId, out ScriptableObject profile)`，其在以下情况返回 `false` 当没有槽位与给定的模块 ID 匹配时。

### 将预设应用到角色

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

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

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

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

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

分配一个 `ConvaiEmbodimentPresetLibrary` 资源（**Assets > Create > Convai > 具身化 > 预设库**) 到 **库** 字段，以启用基于 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/embodiment/embodiment-presets.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
