Player Controller null after RestartPlayer()

I have a simple multiplayer game. When my player dies, the server calls a Player::Die() function which includes this code:


Later my GameMode iterates through the player controllers and sees that he is dead ( It->Get()->GetPawn() is null) and calls RestartPlayer(PlayerController).

After restarting the player, the APawn::Controller value is null in the player’s BeginPlay().

When the player first spawns (before dying) this value is not null in BeginPlay(). But after he dies and the GameMode restarts him, the Controller value is null in his BeginPlay().

Is there any reason why this would happen?

After doing some logging it looks like this is happening for my respawn logic:

SERVER calls DetatchFromControllerPendingDestroy() on client actor
SERVER calls Destroy() on client actor

SERVER UnPossess
SERVER Actor Destroyed
CLIENT UnPossess
CLIENT Actor Destroyed
SERVER BeginPlay (NULL controller)
SERVER Possess Actor

So Possess() gets called after BeginPlay() on the Server and that’s why the controller is null in BeginPlay(). But neither Possess() or BeginPlay() get called on the Client.

I have logic that depends on having a valid controller:


Where should I put the logic that depends on having a valid Controller after respawning?

Found the answer I was looking for… you need to override virtual function:


This is where you would want to do something like attach weapon to first person mesh after respawning.

1 Like

Lifesaver - TYSM