How do you spawn a class chosen in editor with C++?
I have a C++ Pawn class, 'MyPawn'. I have a subclassed blueprint version where I can change the mesh, etc in the editor.
Similarly I also have a Projectile class and a subclassed blueprint version.
I'm trying to set which type of projectile a type of pawn shoots, like so:
This appears fine in the editor and I can select the base projectile class or my blueprinted subclass which has a mesh assigned, etc.
Now, I'm trying to spawn one of those projectiles and I have no idea how to do it. I'm looking at the docs and every version I try doesn't seem to work. I have:
I get the error
For that matter:
In fact, many parts of my code have been getting underlined saying either the 'incomplete class' thing or "undeclared identifier", even when it compiles and runs just fine. I have no idea why and it's completely infuriating. I always seem to get this issue when working with custom enums or structs... it makes intellisense totally break down even if the code actually compiles just fine. Help?
So c++ teach here:
Template functions which is marked with T (in short everything is template function/class etc if you need give something between ) means you need your class as Template. Not your variable, your c++ class!
SpawnActor will give back your spawned projectile as class which you give to template as input :)
Your Code must look in this way:
Or something like that because i dont know your class names, but in short
Between goes your C++ class name, not your file name your class name like APawn, AActor, AMyProjectile, MyProjectile depends on how you named that class :) (check yourclass.h and youl will se after class word ;) )
Next, spawn what you want spawn goes first after (WhichClassWantyouSpawn, location, rotation)
Whichclasswantyouspawn can be a c++ class or a TSubClassOf variable. SpawnActor decide about this which spawn need to place in world :)
Follow this question
Once you sign in you will be able to subscribe for any updates here