I’ve got a class that is a subclass of a subclass of AActor. I want to be able to spawn a BP derived version of the class from a different class. However the AActor* that I assign to the LoadObject is always nullptr.
In the asset there’s a Blueprint and a Class (BlueprintGeneratedClass), there is no actor.
Blueprint is editor-only data that exists for editing (scene view, graphs, compiling…).
Class/BlueprintGeneratedClass is what you use to spawn actors, via World->SpawnActor method.
The naming convention is always the same :
Note that you probably never want to load the Blueprint itself, unless you are working on editor utility tools.
So what you want is probably something like this :
Now, while it should work, this is not the recommended way to do it.
Loading assets via string references like this is not only prone to error, but also doesn’t tell the packager that this asset is needed by the game.
If you don’t have a direct reference to that asset somewhere else then it won’t be packaged in your game and won’t work in your shipping build.
There are two ways to go about this.
Method 1 :
your C++ class responsible for this code must have BP subclass(es). For example let’s say this is AWeaponBase, and this is the code to spawn the projectile. All your actual weapons are gonna be blueprints subclasses of this.
In AWeaponBase header, add a class property like this
Wow, what a morning to wake up to such a well written answer!
If for some odd reason you don’t want to make a BP subclass of this, ie. this is the final class and it is C++ only
I read in a forum on here that BPs are noticeably slower than C++ classes, so I am actually inclined to make C++ only classes when a “template” is not needed. I don’t know if that post was for ue4 or ue5 so it may have been an outdated post though.