Spawn Blueprint from path in c++
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
Spawner.cpp (in constructor)
Spawner.cpp (in another function)
For now i get this error when i try to spawn:
I'm working on a plugin and i get the path from the right click "Get reference"
Thanks in advance for your help.
Edit: sry just saw you do a Plugin you might not need "/Game/" in your Path =)
Hi, I had the same problem, and I found two possible solutions.
1) If your actor is created in the Unreal Editor, then you can simply spawn it by code like this:
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.
2) 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
answered Apr 02 '18 at 10:38 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here