Unreal Engine 5 · Blueprint → C++
Get Player Pawn and Character in Unreal Engine 5 C++UE Docs
The Get Player Pawn and Get Player Character Blueprint nodes map to UGameplayStatics::GetPlayerPawn(this, Index) and UGameplayStatics::GetPlayerCharacter(this, Index) in Unreal Engine 5 C++.
Blueprint node & C++ equivalent
APawn* Pawn = UGameplayStatics::GetPlayerPawn(this, /*PlayerIndex=*/0);
ACharacter* Char = UGameplayStatics::GetPlayerCharacter(this, 0);What do these nodes do?
These nodes return a reference to a player's controlled pawn or character by player index. Index 0 is the first local player. Get Player Pawn returns an APawn*, while Get Player Character returns an ACharacter* for cases where you need character-specific functionality.
They are static helpers, so they need a world context object, which the example provides as this.
How to use it in C++
Call UGameplayStatics::GetPlayerPawn(WorldContextObject, PlayerIndex) or GetPlayerCharacter(WorldContextObject, PlayerIndex). Include Kismet/GameplayStatics.h to access the class. Always null-check the returned pointer, since the player may not be spawned or possessed yet.
Use GetPlayerCharacter when you intend to call ACharacter members; otherwise GetPlayerPawn is the more general choice.
Common mistakes
Assuming the pointer is always valid causes crashes during level startup or after the pawn is destroyed. Also, casting a returned pawn that is not actually your character class will return null, so check the result of any Cast before using it.
Frequently asked questions
How do you get the player pawn in UE5 C++?+
Call UGameplayStatics::GetPlayerPawn(this, 0) with a world context object and the player index, then null-check the result.
What is the difference between GetPlayerPawn and GetPlayerCharacter?+
GetPlayerPawn returns an APawn* for any pawn, while GetPlayerCharacter returns an ACharacter*, which is null if the controlled pawn is not a character.