So I have been trying to solve this problem for the last few days. Basically, I want to make a new blueprint asset through c++ and save it into the content browser in editor. The blueprint should derive from a custom actor class and I want to add actor components to it before saving it.
The current solution I have is using FKismetEditorUtilities::CreateBlueprintFromActor which will take a pointer to an actor in a level and use that as a template to make a blueprint. That works fine and the asset gets created with the correct inheritance. But the only problem is that I can’t seem to add any components to the actor in the level (before trying to create the blueprint). I am trying to call AActor::AddComponentByClass but that does nothing. Upon setting breakpoints I can see that it exits the method because World->bIsTearingDown is true and I am not sure why. I am creating the actor just before trying to add the components, so maybe the actor is not yet initialized correctly?
This is the code in question (DataSpecs->ModuleWall is a TSubclassOf UStaticMeshComponent):
UWorld* World = GEditor->GetEditorWorldContext().World(); AFGLevelModule* LevelModuleInstance = World->SpawnActor<AFGLevelModule>(AFGLevelModule::StaticClass()); LevelModuleInstance->AddComponentByClass(DataSpecs->ModuleWall, false, FTransform(), false);