void ABerserkGameMode::RestartPlayer(AController* newPlayer)
{
	const auto startSpot = FindPlayerStart(newPlayer);
	if (startSpot != nullptr)
	{
		InitStartSpot(startSpot, newPlayer);

		const auto newPlayerController = Cast<ABerserkPlayerController>(newPlayer);
		if (newPlayerController != nullptr)
			newPlayerController->SetInitialLocationAndRotation(startSpot->GetActorLocation(), startSpot->GetActorRotation());
	}
	else LogWarning("Player start not found, failed to restart player.");
}
void AGameModeBase::RestartPlayerAtPlayerStart(AController* NewPlayer, AActor* StartSpot)
{
	if (NewPlayer == nullptr || NewPlayer->IsPendingKillPending())
	{
		return;
	}

	if (!StartSpot)
	{
		UE_LOG(LogGameMode, Warning, TEXT("Player start not found, failed to RestartPlayerAtPlayerStart"));
		return;
	}

	UE_LOG(LogGameMode, Verbose, TEXT("RestartPlayerAtPlayerStart %s"), (NewPlayer && NewPlayer->PlayerState) ? *NewPlayer->PlayerState->PlayerName : TEXT("Unknown"));

	if (MustSpectate(Cast<APlayerController>(NewPlayer)))
	{
		UE_LOG(LogGameMode, Verbose, TEXT("RestartPlayerAtTransform tried to restart a spectator-only player!"));
		return;
	}

	// Try to create a pawn to use of the default class for this player
	if (NewPlayer->GetPawn() == nullptr && GetDefaultPawnClassForController(NewPlayer) != nullptr)
	{
		NewPlayer->SetPawn(SpawnDefaultPawnFor(NewPlayer, StartSpot));
	}

	if (NewPlayer->GetPawn() == nullptr)
	{
		NewPlayer->FailedToSpawnPawn();
	}
	else
	{
		// Tell the start spot it was used
		InitStartSpot(StartSpot, NewPlayer);

		FinishRestartPlayer(NewPlayer, StartSpot->GetActorRotation());
	}
}