Unreal Engine附着组件调用区别
文章目录
- 前言
- 一、AttachToActor
- 二、AttachToComponent
- 核心差异
前言
在 Unreal Engine 中,AttachToActor 与 AttachToComponent 均通过底层调用 USceneComponent::AttachToComponent 实现附着,关键区别在于父组件的指定方式:
一、AttachToActor
默认将目标 Actor 的 根组件(Root Component) 作为父组件。
示例:
EquipmentActor->AttachToActor(TMSCharacter, AttachmentRules, AttachSocketName);
TMSCharacter 的胶囊体组件(通常设为 Root Component)会成为 EquipmentActor 的附着父级。
二、AttachToComponent
显式指定任意场景组件(如骨骼网格体)作为父组件。
示例:
EquipmentActor->AttachToComponent(Mesh, AttachmentRules, AttachSocketName);
直接绑定到角色的骨骼网格组件(如 Mesh),实现更精细的骨骼级附着。
核心差异
AttachToActor 隐式使用 Actor 的 Root Component 作为附着点,而 AttachToComponent 允许显式控制目标组件。若需绑定到骨骼插槽,必须使用 AttachToComponent 并指定骨骼网格体组件。