RealDocs

UGameplayStatics::GetPlayerPawn

function Engine Blueprint Since unknown
#include "Kismet/GameplayStatics.h"
Access: public Specifiers: static

Description

Returns the APawn possessed by the given local player controller. More permissive than GetPlayerCharacter — works for any pawn type, not just ACharacter.

Signature

static ENGINE_API APawn* GetPlayerPawn(const UObject* WorldContextObject, int32 PlayerIndex)

Parameters

Name Type Description Default
WorldContextObject const UObject* Any valid UObject in the world.
PlayerIndex int32 Zero-based local player index.

Return Type

APawn*

Caveats & Gotchas

  • Returns null if the controller has no possessed pawn (e.g. spectating, or between respawns).
  • Prefer GetPlayerCharacter when you know the pawn is an ACharacter — it avoids a Cast. Use GetPlayerPawn when the pawn type may vary (vehicles, spectators, etc.).

Example

Get pawn location regardless of class C++
APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(this, 0);
if (IsValid(PlayerPawn))
{
	FVector PlayerLocation = PlayerPawn->GetActorLocation();
	DrawDebugSphere(GetWorld(), PlayerLocation, 50.0f, 12, FColor::Green, false, 2.0f);
}

Version History

Introduced in: unknown

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.