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

Controlling Pawns Through the PlayerController

You will master the PlayerController class to handle player input and define the bridge between a human user and their physical pawn.

In this lesson, you will learn how the PlayerController acts as the vital bridge between a human player's physical input and the virtual Pawn residing in your game world.

The Role of the PlayerController

Up until now, you have learned about managing game rules and state. However, a Pawn—the physical representation of a player—cannot "think" on its own. It is simply a container for a mesh and movement logic. The PlayerController is the "brain" that lives on the client side, listening for button presses and joystick movements to tell the Pawn what to do.

Think of it this way: The Pawn is a car, and the PlayerController is the driver. The car (Pawn) knows how to accelerate and steer, but it doesn't know when to do those things until the driver (PlayerController) decides to press the pedal.

Possessing the Pawn

When a game begins, the GameMode decides which Pawn to spawn and then "possesses" it with a PlayerController. Possession is the engine's way of linking a specific controller to a specific physical body. Once possessed, any input handled inside that PlayerController can be routed directly to the Pawn.

For example, if you want to handle movement, you define your input logic inside the PlayerController class. Here is a simplified conceptual view of how you might trigger an action on a pawn:

void AMyPlayerController::SetupInputComponent()
{
    // Bind the 'Jump' action to a function in your controller
    InputComponent->BindAction("Jump", IE_Pressed, this, &AMyPlayerController::HandleJump);
}

void AMyPlayerController::HandleJump()
{
    // Access the pawn currently possessed by this controller
    APawn* MyPawn = GetPawn();
    if (MyPawn)
    {
        // Tell the pawn to perform the jump action
        MyPawn->Jump();
    }
}

By decoupling the controller from the pawn, you gain massive flexibility. You could swap the Pawn (e.g., exiting a vehicle to walk on foot) while keeping the same PlayerController, ensuring the player’s settings, UI, and input preferences remain consistent.

Key Takeaway: The PlayerController serves as the permanent interface for the human user, while the Pawn serves as the temporary physical body that the controller "possesses" to interact with the world.