Download

Crashing when respawning a client, not server.

When my Pawn dies I call this function:



void ATestPawn::Explode()
{
	GEngine->AddOnScreenDebugMessage(1, 15.0f, FColor::Red, "I'm dead.");

	ShipMeshComponent->SetVisibility(false);
	UnPossessed();

	auto gameMode = GetWorld()->GetAuthGameMode();
	auto TestGameMode = Cast<ATestGameMode>(gameMode);
	TestGameMode->RegisterPawnDeath(PlayerController);
	Destroy();

}


It goes into my game mode:



void ATestGameMode::RegisterPawnDeath(APlayerController* PlayerController)
{
	//if (!PlayerController) return; //PlayerController is NULL for clients NOT for server
	FActorSpawnParameters params;
	params.bNoCollisionFail = true;
	params.Owner = this;
	params.Instigator = NULL;
	params.bDeferConstruction = false;

	auto PlayerStart = GetWorld()->SpawnActor<APlayerStart>(APlayerStart::StaticClass(), FVector(0, 0, 210.0f), FRotator::ZeroRotator, params);

	PlayerController->Possess(SpawnDefaultPawnFor(PlayerController, PlayerStart)); //It crashes on this Line PlayerController is NULL
}


I get a crash on the last line. PlayerController is NULL for clients but not for server. I am using a custom player controller.

I am getting stuck on how this respawning, player controllers, and game mode stuff. Any help would be appreciated.

The GameMode class instance only exists on the server for network games.
I suspect auto is doing something clever here.

Take a look at the ‘Shooter Sample’ in the UE4 market place - its free.