(UE5) How to spawn blueprint actor with C++?

You must define a TSubclass of the blueprint you want to spawn and add the EditDefaultsOnly UPROPERTY like this:

UPROPERTY(EditDefaultsOnly)
TSubclassOf<myBlueprintBaseClass> my_BP_Class;

EditDefaultsOnly lets you pick the class in the editor. So If you do this and compile, then go back to the editor and you will see a slot select your actual blueprint class

then for spawning do this:

myBlueprintBaseClass* mySpawn = GetWorld().SpawnActor<myBlueprintBaseClass>(my_BP_Class,pos,rot,SpawnParams);

Good luck!

Dany

13 Likes