Why is SpawnActor() returning NULL?

Blockquote

I am spawning two pawns in the BeginPlay() in my game mode class like so:

	FActorSpawnParameters SpawnParams;
	SpawnParams.Owner = this;
	SpawnParams.Instigator = Instigator;
	FVector LeftPawnLocation = FVector(0, 2450, 1500);
	FVector RightPawnLocation = FVector(0, -2450, 1500);
	FRotator PawnRotation = FRotator(0.0f, 0.0f, 0.0f);
	UWorld* const PongWorld = GetWorld();

	if (PongWorld) {
		FirstPlayer = PongWorld->SpawnActor<APongPaddlePawn>(LeftPawnLocation, PawnRotation, SpawnParams);
		SecondPlayer = PongWorld->SpawnActor<APongPaddlePawn>(RightPawnLocation, PawnRotation, SpawnParams);
	}

When I debug, i try to set the size of the pawns of FirstPlayer and SecondPlayer and they are both NULL. I can see the pawns showing up in my game. Why are they both NULL?

Try giving the SpawnActor the class you want to spawn. For example:

// h
UPROPERTY()
TSubclassOf<APongPaddlePawn> PongPaddlePawnClass;

// cpp
FirstPlayer = PongWorld->SpawnActor<APongPaddlePawn>(PongPaddlePawnClass, LeftPawnLocation, PawnRotation, SpawnParams);
1 Like

That did it thanks!