What all is needed to respawn a multiplayer pawn

Hey guys. I’ve been trying get my multiplayer stuff up and running for awhile but I’m stuck.

I cannot figure out how to get death and respawning working.

Right now I have a pawn, a custom player controller (I’m doing inputs through this), and a custom game mode.

When I die, I try to give the game mode my player controller but I get crashes.

Can someone provide an explanation of how to do this? What classes do I need? What information do I need to communicate between the classes? How do I store my player controllers to pass to the game mode? Does the game mode already have a list of all player controllers? Really, all I know is how to replicate functions such as movement, I am lost on what I need to make multi-player work.

The short version: all you need is a replicated Pawn of any type and call PlayerController::Possess on it.

GameMode has some utilities that help you like:

  • Setting the pawn class and player controller class in the editor
  • The function SpawnDefaultPawnFor which spawns a pawn of your selected class at a random unoccupied PlayerStart
  • The function SpawnController which spawns a player controller of your selected class when a new player joins

But you can override them or even completely ignore them as long as you spawn a pawn and call PlayerController::Possess on it. As for how to access existing PlayerControllers (for currently connected players), you can use UGameplayStatics::GetPlayerController which is the C++ for the blueprint node GetPlayerController. On the other hand, respawning is usually triggered by the pawn or its controller, so then you already know which controller you want.

You can call AGameMode::RestartPlayer to respawn your player in the default way, the same spawn functionality as when it joins the game for the first time. Hope that helps you get started.

I really appreciate your help. I’ll keep at it and figure this out. Thank you very much for your help.