GameMode->RestartPlayer() doesn't do anything!

***** NEWS *****

Also, in the code of these 3 functions, I don’t see the part where the Pawn is “transported” towards the PlayerStart location.

I only see the code setting the Pawn’s rotation

In fact when the Character dies, he looks up! If I’m facing the ground while dying, once I’m dead I look forward!

So the RestartPlayer() is only setting my rotation. not position!

[USER=“1384187”]Joe Wilcox WisE[/USER]

There isn’t any teleportation… a new pawn is spawned.

The flow goes like this in a multiplayer game.
1. Client calls PlayerController::ServerRestartPlayer()
2. PlayerController::ServerRestartPlayer() makes sure the player can restart, unposseses any possessed pawn and calls GameMode::RestartPlayer()
3. GameMode::RestartPlayer find a start spot then calls GameMode::RestartPlayerAtPlayerStart()
4. Since the controller no longer has a pawn, the second branch is hit and SpawnDefaultPawnFor() is called, a pawn is created and returned, then the player controller is assigned that pawn with SetPawn().

Hope that helps. Btw… spending the HD space is worth it :slight_smile:

3 Likes

Ok, then I made it this way


myController->UnPossess();
myGameMode->RestartPlayer(myController);

This way I finally manage to **respawn **to a new PlayerStart

The problem is… on the Server window it works. On the client, it crashes!

Any idea?

The reason of the crash is this line, inside RestartPlayerAtPlayerStart()



NewPlayer->SetPawn(SpawnDefaultPawnFor(NewPlayer, StartSpot));


Why are you running it on the client anyway? Just FYI, the proper way to restart a remote player is to call PlayerController->ServerRestartPlayer().

1 Like

Well… the Die() function is for everyone. When a player dies, whoever it is, client or server, it needs to execute that code. (But the function runs on the server, since, as you may remember, there’s the Authority check at the top)

Yes I already tried that



APAPlayerController* myController = Cast<APAPlayerController>(GetController());
myController->ServerRestartPlayer();


And** it does absolutely nothing**

bump

Any other tip? I really can’t get this work!

Add UnPossess(); before using RestartPlayer()

Did you get it to work?

If you need to forcefully restart the player in your game mode, you can use the Reset() method from APawn class. For example, this is how you restart all players:

for (FConstPlayerControllerIterator Iterator = GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator)
{
	APlayerController* PlayerController = Iterator->Get();
	if (APawn* Pawn = PlayerController->GetPawn())
	{
		Pawn->Reset();
	}
	RestartPlayer(PlayerController);
}