Download

Getting player controller to call RestartPlayer()

Hey Guys,

Multi-player question:

I am trying to respawn my Pawn using the correct way, which I think is RestartPlayer() a GameMode function. GameMode is server only, So I can’t get a game mode instance in my Pawn or my PlayerController class (Clients). How do I get the player controller to the GameMode so I can call that function?

I figure there has to be some way for the player controller to indicate to the server that it needs a new pawn, but I just can’t figure it out.

Thanks guys.

You may create a server function on your PlayerController or Pawn.


UFUNCTION(Server, Reliable, WithValidation)
void ServerRequestRespawn();

It will be called on server instance of your game, where GameMode is accessible, so you can call RestartPlayer from it.

Or you can write logic, that determines whether a player need a new Pawn inside a PlayerController.
Since every player’s PlayerController exists on server, you just need to wrap your respawn specific logic in Role checking block:


if(Role == ROLE_Authority)
{
    // your respawn specififc logic
}

This is awesome. I think you are explaining exactly what I need to do. I’m going to try several things based on your suggestions. Thank you very much.

Thanks again man! you really helped me out. I made some good progress because of your suggestions. Thank you very much. Things are making a lot more sense now.