How do I create a BluePrint Object in c++?

I have a C++ class called Attachment, and I use that as a base class for several Blueprint classes.

Now from C++ I would want to create an object from one of those blueprint classes. Normally I would use the ConstructObject, but I have no reference to the blueprint class in C++.

How can I do this? Or am I using wrong design principles here?

Thanks!

Easiest way is to make UClass* or TSubclassOf variable that you can edit in editor, then you can use that property either in NewObject (you should use this function insted) or SpawnActor, it most easiest and most safe solution, not to mention good if you got artists that does not look in to code. You can make property in AGameMode, or alter World Settings by creating own UWorldSettings and place varable there.

The harder way is grabing UBlueprint asset (same as you do with meshes) and equireing generated UClass*, it was explained a lot of times so i simply paste link:

I also think there was some issue with this way on packaging so watch out on that, your blueprint need to be refrenced by something in order to be packaged.

1 Like