Need help spawning a Blueprint that inherits from a C++ UObject class.
Hey, i'm having some trouble spawning a blueprint from my C++ code and would appreciate some help with it.
This is the base C++ class of the blueprint i wish to spawn. I have created a blueprint that inherits from this class.
But i have gotten stuck at this next part, in my GameMode i try to spawn the blueprint but cannot figure out how i should do this. I can spawn the class just fine if i just spawn the C++ version of the class using this.
I tried using this to spawn the blueprint, but it did not work. (I check if the WaypointManager is valid)
Would be great if someone could help me out by telling me how you go about spawning blueprints that inherit from UObject in c++.
asked Oct 17 '15 at 12:52 PM in C++ Programming
SpawnActor is used to spawn an actor, UObject's are not actors they are objects. To instantiate an UObject you should use NewObject and hold the instance in a property field of some of your other classes.
Now that you know how to create a new object let's check on spawning a Blueprint class. The first thing we have to clear out is to outline that a Blueprint is an asset, it's content and content has some special treating when creating a packaged game. All content in your project get's cooked, cooking is just a process of ripping of some editor specific data from your assets and prepare it for faster loading (on optical media content should be aligned by 16 bits to lower seek times for example). So what the engines does is to scan you project and to cook only content that is actually referenced so that you package only the stuff you are actually using. That is actually nice and useful but it comes with an issue: when you are running in the editor you have uncooked data and access to everything so many people fail to package their game because their stuff is not available when they create a release of their project.
To solve the cooking Odyssey you have to simply ensure your content is referenced where you need it. We will show a simple way to reference your Blueprints based on the Actor class (you can adapt it for your own base classes though).
Add a property to your C++ class to hold a class of your BP.
I added the snippet above into a child of AGameMode and your should got something like this:
Then I just created a new BP that inherits from UObject directly and selected it from the drop down:
The next step is to use that property to spawn a new
We just use our property to create a new object within the Transient package, this is important when creating objects in run-time to respect the GCs refernce chain.
But I do not want to reference every thing always
Now that you know the basics I'll post some references to get you started referencing you assets painlessly and to load them in blocking and non-blocking fashion.
To be able to load a class being it blocking or non-blocking the content needs to be cooked forehand. You could for example just create some directories that will get cooked always and store your dynamic content in those folders.
I guess what you want is create a class from a blueprint that you created in the editor?
I've managed this way:
where /Game/ is your Content directory, I suppose.
Follow this question
Once you sign in you will be able to subscribe for any updates here