Spawning child actors for use in the editor

I did this in a c++ actor. ( in PostEditChangeProperty )
And then created a blueprint inheriting from this actor, and then simply dropping the actor in the world, then after clicking a boolean, the following code runs, and spawns stuff, even after ue is closed/reopened the spawned actors remain, so it does get serialized as well.

 #if WITH_EDITOR
  UChildActorComponent* ChildActor = NewObject<UChildActorComponent>(GetRootComponent());
  ChildActor->SetMobility(EComponentMobility::Static);
  ChildActor->SetChildActorClass(ClassToSpawn::StaticClass());
  ChildActor->CreateChildActor();
 #endif
1 Like