UE 分层动画与 Animation Layer Interface 完全指南
前言
UE 动画系统最强大的特性之一就是分层。一个角色可以同时播放多套动画——下半身在走路,上半身在射击或持枪,表情在变化,手部在交互。Animation Layer Interface(动画层接口)正是连接这些分层动画系统的桥梁。理解分层,就理解了 UE 动画系统一半的威力。
一、分层动画基础
1.1 什么是分层动画
UE 的动画分层基于 Additive(叠加) 和 Override(覆盖) 两种模式:
| 模式 | 效果 | 典型用途 |
|---|---|---|
| Override | 完全替换下层动画 | 上半身攻击覆盖移动 |
| Additive | 在下层动画基础上叠加 | 受伤抖动、表情变化 |
分层由 AnimGraph 中的 Layer joints(骨骼) 决定应用范围。
1.2 分层架构图
Output Pose
↑
Base Layer (Locomotion: Walk/Run/Jump) ←─────────┐
↑ │
Full Body Additive Layer (受伤抖动) ←─────────┤
↑ │
Upper Body Layer (持枪/射击) ←────────────────┘
↑
Aim Offset (瞄准偏移) ←──────────────────────────┘
1.3 Blend Layer
// C++ 中控制分层权重
UAnimInstance* Anim = GetMesh()->GetAnimInstance();
UAnimLayerIn* UpperBodyLayer = Anim->GetAnimationLayerInterface("UpperBody");
// 设置 Additive 权重(0=完全叠加,1=完全覆盖)
UpperBodyLayer->SetBlendParameter(0.7f);
二、Animation Layer Interface
2.1 为什么需要 Layer Interface
在没有 Layer Interface 之前,AnimBP 的层是写死的——你想在多个角色间复用同一套上半身动画,必须复制整个 AnimBP。Layer Interface 解决了这个问题:它定义一组「插槽」,任何 AnimBP 都可以实现这些插槽,Montage 或外部 AnimBP 向插槽注入动画。
Layer Interface "UpperBody"
↓
Slot: "UpperBodySlot" ← 接收任何上半身动画
Required Bones: Spine_01, Spine_02, Clavicle_L/R, Arm_L/R
2.2 创建与使用流程
- 创建 Layer Interface:Content Browser → Animation → Animation Layer Interface
- 定义 Slot:在 Interface 中添加
UpperBodySlot、LowerBodySlot等 - 在目标 AnimBP 中实现 Interface:「My Blueprint → Interfaces → Implemented Interfaces」
- 在 AnimBP 中添加「Layered Bone」节点,连接到对应骨骼
- 在 Montage 或其他 AnimBP 中播放到该 Slot
2.3 Layered Bone 节点
AnimGraph:
Base Pose (Locomotion)
↓
Layered Bone (Spine_01, weight=1.0)
↓
Additive + Pose Asset
↓
Output Pose
关键参数:
– Layer Setup:选择受影响的骨骼范围(例:Spine_01 → Spine_03 = 整个躯干)
– Blend Time:过渡到该层的时间
– Additive Settings:是 Additive 还是 Override
三、Slot 节点与 Montage 播放
3.1 Slot 节点
Slot 是 Layer 中的「插孔」,专门用来接收 Montage 的动画:
AnimGraph:
State Machine (Base Locomotion)
↓
Slot "UpperBodySlot" ← Montage 动画注入到这里
↓
Output Pose
3.2 Montage 播放到指定 Slot
// C++:播放 Montage 到指定 Slot
UAnimMontage* Montage = LoadObject<UAnimMontage>(nullptr, TEXT("/Game/Animations/Montage_UpperBody"));
if (AnimInstance) {
AnimInstance->Montage_Play(Montage, 1.0f);
// 指定 Slot 名称
FName SlotNodeName = FName("UpperBodySlot");
AnimInstance->Montage_SetSlotWeight(Montage, SlotNodeName, 1.0f);
}
3.3 多 Slot 同时播放
一个 Montage 可以有多个 Slot:
Montage:
Slot 1: "FullBody" → 全身动作(翻滚、攀爬)
Slot 2: "UpperBody" → 上半身动作(射击、持枪)
Slot 3: "Face" → 表情动画
这样三个 Slot 可以独立播放、相互不干扰。
四、Additive 动画制作
4.1 什么是 Additive 动画
Additive 动画存储的是相对于参考帧的差值(位移、旋转),而不是绝对姿势。这使得 Additive 动画可以在任何基础姿势上叠加:
基础姿势 A (Idle) + Additive 动画 = 变化后的 Idle
基础姿势 B (Walk) + Additive 动画 = 变化后的 Walk 上叠加效果
4.2 适用场景
| 场景 | Additive 类型 |
|---|---|
| 角色受伤抖动 | CA_Additive |
| 呼吸起伏 | CA_Additive |
| 表情动画 | CA_AdditiveFace |
| 瞄准偏移(Aim Offset) | RTG_Interpolate |
4.3 Aim Offset 创建流程
Aim Offset 用于第三人称射击游戏的瞄准方向:
- 在 Model Editor 中为每个可能方向(8方向 × 上下角度)烘焙姿势
- 创建 Aim Offset 1D 或 2D 资产
- 在 AnimBP 中:
Get Aim Angle→Calc Aim Offset→Layered Bone Apply Aim
// 计算瞄准偏移
FRotator AimAngle = GetOwningActor()->GetActorRotation() - GetOwningActor()->GetBaseAimRotation();
AnimBP->SetBaseAimAngle(AimAngle.Yaw / 360.0f, AimAngle.Pitch / 180.0f);
五、实战:构建上下身分层 AnimBP
5.1 目标架构
Base Pose
↓ (下身 Locomotion: Walk/Run)
State Machine (下身)
↓
Additive Blend (下身叠加:呼吸、脚步声音)
↑
← Layered Bone (Spine_01, Additive)
↑
来自 Slot "UpperBodySlot" 的 Montage
(打拳、射击、持枪)
↑
← Layered Bone (Clavicle_L/R, Override)
↑
Aim Offset (瞄准动画)
5.2 关键配置
Layered Bone (UpperBody):
- Bone: Spine_01
- Blend Depth: 2 bones up
- Additive: True
- Mesh Space: True
Layered Bone (AimOffset):
- Bone: Clavicle_L
- Blend Depth: Clavicle_L
- Additive: True
- Mesh Space: True
5.3 常见坑
坑 1:Layer 没有生效
→ 检查 Layered Bone 节点的 Weight 是否为 1.0,Blend Time 是否太长
坑 2:上下身动画冲突
→ 在两个 Layered Bone 之间添加 Apply Mesh Space Additive,确保叠加方向正确
六、总结
Animation Layer Interface 是 UE 动画系统「模块化」的体现:
– Interface 定义插槽,AnimBP 实现插槽
– Slot 接收 Montage,Montage 可以在任意 AnimBP 上播放
– Additive 动画叠加在任何基础姿势上,不破坏原有动作
– Aim Offset 是第三人称射击游戏的核心,用好分层事半功倍
掌握分层后,就可以构建真正模块化、可复用的动画系统——这也是 AAA 游戏动画系统的标准做法。
本文收录于 Matrix4x4 AI 编程与游戏开发资源库