构造函数中添加组件:
StaticMeshComponent =CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaitcMeshComponent"));
Runtime状态下添加组件:
//NewObject时一定要传入outer*,否则在编辑器中无法显示 StaticMeshComponent = NewObject<UStaticMeshComponent>(this,TEXT("StaticMeshComponent")); this->AddOwnedComponent(StaticMeshComponent); StaticMeshComponent->RegisterComponent();//重要 this->SetRootComponent(StaticMeshComponent);