Search code examples
c++unreal-engine4

Unreal Engine Spawning Actors


FActorSpawnParameters s;
FVector v(0, 0, 0);
FRotator r = FRotator::ZeroRotator;
ATestPawn *test = GetWorld()->SpawnActor<AActor>(ATestPawn::StaticClass(),v,r,s);

This is the code that I have, when I check the pointer after the spawn actor line it is a null pointer, meaning that the actor did not spawn, what am I doing wrong. I have looked at many a video, and the documentation and there is nothing about it not working, only that it returns a pointer


Solution

  • APawn defaults to

    SpawnCollisionHandlingMethod = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButDontSpawnIfColliding;
    

    If you try to spawn it in a position where it is colliding with something else, and it can not adjust its position so that it doesn't collide, it will not spawn.

    To override this, you can either change the default SpawnCollisionHandlingMethod on your ATestPawn, or change the value in your FActorSpawnParameters.