Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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:

 TSubclassOf<MyProjectile> ProjectileType;

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:

 GetWorld()->SpawnActor<ProjectileType>(ProjLoc, GetActorRotation());

I get the error 'UWorld::SpawnActor': no matching overloaded function found.

For that matter: GetWorld() is underlined with an error that says pointer to incomplete class type is not allowed

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?

Product Version: UE 4.16
more ▼

asked Jul 12 '17 at 06:28 AM in C++ Programming

avatar image

25 4 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first


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 :)

more ▼

answered Jul 12 '17 at 07:27 AM

avatar image

1.5k 15 9 34

avatar image kenmorechalfant Jul 13 '17 at 01:41 AM

Thank you, I got it to work.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question