ue4 动态创建Component

  1. 代码示例
    USkeletalMeshComponent* BlendComponent = NewObject(SharingActor, BlendComponentName);
    BlendComponent->RegisterComponent();
    BlendComponent->SetRelativeLocation(SpawnLocation);
    BlendComponent->SetSkeletalMesh(SkeletalMesh);
  2. 关键点:不管BlendComponent是否是类成员变量且变量有UPROPERTY修饰,都需要调用RegisterComponent函数,否则有些变量不会实例化,会出错;如果上述代码不调用RegisterComponent,BlendComponent->GetAnimInstance()返回的值将永远为空
  3. 源代码证据:在这里插入图片描述
    创建组件需要注册,否则不显示

猜你喜欢

转载自blog.csdn.net/qq_21919621/article/details/106245398