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

I am trying to spawn in blueprint class (a model imported from outside the unreal engine) in c++.
This model is stored as a blueprint class which i can drop into the world inside the editor.
It might just be a simple/stupid question, but since it was made inside the editor, i don’t know how i would use this inside the c++ class i which i want to spawn the models from.

However, i now need to spawn X amount of them in a somewhat random location which just seems easiest by using a c++ class, but if it is easier doing this using a blueprint, I’m open for suggestions.

So my question is, what is the best way going about spawning my model blueprint class, or how do i get hold of this blueprint class in my c++ class?

Hi,

static ConstructorHelpers::FObjectFinder<YourObjectType> YourVaraibleName(TEXT("PathToObject"));
YourObjectType* Var = YourVaraibleName.Object;

You can get the path by clicking on yourn Blueprint Class and select “Copy Reference”

You will have to modify some " ’ " to get it working and remove the “Blueprint”!

ex:

ConstructorHelpers::FObjectFinder<USoundCue> CueTarget(TEXT("SoundCue'/Game/Audio/ExplosionOnShip/explosions_onship_Cue.explosions_onship_Cue'"));

Edit:
My code works in the constructor. I don’t know if you can use it in any function.

Edit2:

I think you are searching something like this

UClass* var = StaticLoadClass(YourClassType::StaticClass(), nullptr, TEXT("Path"));

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”

I would not recommend this, since having direct paths in cpp is always a bit dirty. Also you would have to recompile every time you change the class. I added an answer, that is cleaner and easier to use.

Sorry for the late reply, but how would i derive the class to C++ file? would that just be making an empty c++ file and then linking it too this blueprint class?