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?
asked Mar 03 '17 at 02:57 PM in C++ Programming
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:
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:
Or, if your class is an actor, you would of course use "SpawnActor"
answered Mar 03 '17 at 06:27 PM
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"!
Edit: My code works in the constructor. I don't know if you can use it in any function.
I think you are searching something like this
Follow this question
Once you sign in you will be able to subscribe for any updates here