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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Having trouble with World->SpawnActor argument

I'm trying to write a generic function that, when handed an Actor (or a child class/blueprint thereof), will spawn that actor at some arbitrary location:

 AActor* USpawnManager::SpawnActor(AActor* ActorToSpawn, FVector SpawnLocation){
     if (World != nullptr && ActorToSpawn != nullptr){
         AActor* tempActor = World->SpawnActor(ActorToSpawn, &SpawnLocation);
         return tempActor;
     return nullptr;

This looks right to me, but it throws an error which makes me assume my syntax is wrong: "'AActor UWorld::SpawnActor(UClass ,const FTransform ,const FActorSpawnParameters &)' : cannot convert argument 1 from 'AActor ' to 'UClass *' ". This makes it seem like it wants a uclass instead of an actor, but if I try giving it something like Cast(ActorToSpawn), the entire program crashes. Am I making an obvious mistake, or is GetWorld()->SpawnActor not the right way to be spawning actors in the first place?

Product Version: UE 4.9
more ▼

asked Sep 15 '15 at 12:22 PM in C++ Programming

avatar image

251 95 66 83

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

1 answer: sort voted first

Instead of

 AActor* ActorToSpawn


 TSubclassOf<AActor> ActorToSpawn
more ▼

answered Sep 15 '15 at 12:35 PM

avatar image

3.5k 152 29 318

avatar image HInoue Sep 15 '15 at 12:50 PM

That does the trick perfectly!! Thank you very much :)

(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