Course contentsShow
← Unreal Engine Game Development
Lesson 110 of 8802. The Gameplay FrameworkFree lesson

Handling Controller Persistence During Pawn Death

Learners will design systems to retain controller state and data when a character is destroyed and a new one is spawned.

In this lesson, you will learn how to bridge the gap between a dying character and a respawned one so that your player doesn't lose their identity or data.

The Problem: The "Floating" Controller

When a Pawn is destroyed (for example, when its health reaches zero), the PlayerController that was "possessing" it suddenly loses its physical body. By default, the PlayerController remains active, but it is now "unpossessed." If you simply spawn a new Pawn, your PlayerController will still be sitting in empty space, unable to send movement commands or input to the new character.

To create a seamless respawn experience, we must explicitly re-link the existing PlayerController to the newly spawned Pawn.

Orchestrating the Hand-off

Since the PlayerController survives the destruction of the Pawn, it acts as the perfect "anchor" for your player's data. To handle this flow, we usually use the GameMode. Here is the logic flow:

  1. Detection: The Pawn dies and calls a "Restart" request to the GameMode.
  2. Cleanup: The old Pawn is destroyed, but the PlayerController remains alive in the world.
  3. Instantiation: The GameMode spawns a new Pawn at a PlayerStart location.
  4. Repossession: The GameMode instructs the existing PlayerController to possess the new Pawn.

You can implement this in your GameMode override like so:

// Logic inside your GameMode class
void AMyGameMode::RestartPlayer(AController* NewPlayer)
{
    // 1. Spawn the new pawn
    APawn* NewPawn = GetWorld()->SpawnActor<APawn>(DefaultPawnClass, SpawnLocation, SpawnRotation);
    
    // 2. Re-link the existing Controller to the new Pawn
    NewPlayer->Possess(NewPawn);
}

By using the Possess function, the PlayerController automatically routes its internal input buffers to the new Pawn’s movement components. Because the PlayerController never stopped existing, any local variables you stored on it (like current score or team ID) remain perfectly intact, effectively "transferring" the player's soul into their new body.

Key Takeaway: Because the PlayerController persists independently of the Pawn, you must explicitly call Possess() on the existing controller after spawning a replacement Pawn to restore input functionality.