UE4C++ 添加组件

构造函数中添加组件:

StaticMeshComponent =CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaitcMeshComponent"));

Runtime状态下添加组件:

//NewObject时一定要传入outer*,否则在编辑器中无法显示
StaticMeshComponent = NewObject<UStaticMeshComponent>(this,TEXT("StaticMeshComponent"));
this->AddOwnedComponent(StaticMeshComponent);
StaticMeshComponent->RegisterComponent();//重要
this->SetRootComponent(StaticMeshComponent);
上一篇:UE4垃圾回收


下一篇:UE4中出现如下报错