Download

How to use SpawnActor?

Hello,

I created a new C++ actor, and I am trying to use this actor to spawn other actors. I got something like this:


						
Afloor_50x50* TestSpawn;
TestSpawn = GetWorld()->SpawnActor<Afloor_50x50>(SpawnLocation, Rotation);


I am not sure if I did this correctly… Afloor_50x50 is another C++ actor I’ve created and assigned to a mesh. This causes the engine to crash.

How can I properly use SpawnActor? Greatly appreciated! :wink:

Have you tried using StaticClass()? Like so:


TestSpawn = GetWorld()->SpawnActor<Afloor_50x50>(Afloor_50x50::StaticClass(), SpawnLocation, Rotation);

Solved. Thank you for your help!
Also, I placed the SpawnActor code in my actor’s constructor. Makes sense it would crash I guess, if spawned object wasnt constructed yet.