如何在Actor的构造函数中添加该组件,或者在蓝图中添加该组件并设置它的属性
时间: 2024-02-28 17:54:19 浏览: 137
在Actor的构造函数中添加`USkeletalMeshComponent`的示例代码如下:
```cpp
// 在Actor的构造函数中添加USkeletalMeshComponent
AMyActor::AMyActor()
{
// 创建USkeletalMeshComponent
USkeletalMeshComponent* SkeletalMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("SkeletalMeshComponent"));
// 将新创建的组件设置为RootComponent
RootComponent = SkeletalMeshComponent;
// 设置组件的默认SkeletalMesh
static ConstructorHelpers::FObjectFinder<USkeletalMesh> SkeletalMeshAsset(TEXT("/Game/MySkeletalMesh"));
if (SkeletalMeshAsset.Succeeded())
{
SkeletalMeshComponent->SetSkeletalMesh(SkeletalMeshAsset.Object);
}
}
```
在上面的代码中,我们首先使用`CreateDefaultSubobject`方法创建了一个新的`USkeletalMeshComponent`,然后将该组件设置为`RootComponent`。最后,我们使用`SetSkeletalMesh`方法设置组件的默认`SkeletalMesh`。
如果你想在蓝图中添加`USkeletalMeshComponent`并设置它的属性,可以在蓝图编辑器中拖放一个`SkeletalMeshComponent`到你的`Actor`上,然后在`Details`面板中设置它的属性。你可以设置`SkeletalMesh`,`Animation Blueprint`,`Physics Asset`等属性。
阅读全文
相关推荐

















