I’m trying to spawn an Blueprint Actor directly from C++ code, i found many answers to this question but none works (the only one was to add _C at the end of the path, but it doesn’t work when the game is packaged
I Have a “TargetItem” actor class and a blueprint parented from it. And i want to spawn it from another class
The pre-requisite is that your actor is replicated. Please note that actors deriving from AActor are not replicated by default, so you need to add in their constructor:
bReplicates = true;
or within the editor you should flag your actor as “Replicates”. It is one of the properties in the details panel.
If you want to create your actor completely within C++, and you have only the StaticMesh and the Material in the Editor (this was my case), you can create it like this:
Also in this case the pre-requisite is that your actor is replicated. Same case for case 1.
If your actor is invisible client side, means you didn’t replicate it, or you didn’t set the position properly. Please note the SetWorldLocation call despite the fact you are already giving the location in the spawnactor command. For me it works only if I call explicitely SetWorldLocation
This is the most universal and easy to use way to load blueprint classes. Works in constructors and outside. You don’t need the .BP_TargetItem_C after package path.
You need to add CoreUObject to the dependencies of your project.