- 代码示例
USkeletalMeshComponent* BlendComponent = NewObject(SharingActor, BlendComponentName);
BlendComponent->RegisterComponent();
BlendComponent->SetRelativeLocation(SpawnLocation);
BlendComponent->SetSkeletalMesh(SkeletalMesh); - 关键点:不管BlendComponent是否是类成员变量且变量有UPROPERTY修饰,都需要调用RegisterComponent函数,否则有些变量不会实例化,会出错;如果上述代码不调用RegisterComponent,BlendComponent->GetAnimInstance()返回的值将永远为空
- 源代码证据:
创建组件需要注册,否则不显示
ue4 动态创建Component
最新推荐文章于 2023-07-11 20:03:24 发布