How to spawn in a Blueprint class made in the editor using c++?

Here is a way that lets you set the class in editor with nice filters, and prevents any paths from beeing involved in C++ (which is always a bit dirty):

Derive the Blueprint-Class that you want to spawn on a c++ class (might just be empty, doesn’t matter).

Add this to the class that spawns the objects:

UPROPERTY(EditAnywhere)
TSubClassOf<YourCppBaseClass> ClassToSpawn;

Since it is UPROPERTY(EditAnywhere), you can now find an instance of the object, that will spawn your class and edit the “ClassToSpawn” Property. There will be a drop-down-menu, where you can select the class that you want to spawn. Only Classes (Blueprint and C++) that derive from “YourCppBaseClass” will be shown.

In Code, you can then just spawn stuff like so:

YourCppBaseClass* instance = NewObject<YourCppBaseClass>(this, ClassToSpawn);

Or, if your class is an actor, you would of course use “SpawnActor”