APlayerState::GetPawn
#include "GameFramework/PlayerState.h"
Access: public
Specifiers: UFUNCTIONBlueprintCallable
Description
Returns the pawn currently associated with this PlayerState, or null if the player is not possessing a pawn. This is the preferred way to find a player's pawn when you only have a PlayerState reference.
Caveats & Gotchas
- • Returns null on clients that do not have the pawn replicated to them, even if the server has a valid pawn for this player. APlayerState is always relevant to all clients but the pawn itself may not be.
- • A templated overload GetPawn<T>() is also available for a one-line cast: PS->GetPawn<AMyCharacter>(). This returns null if the cast fails rather than asserting.
- • The pawn pointer is stored in the private PawnPrivate member and is updated via the engine-internal FSetPlayerStatePawn helper. Do not attempt to set it directly from game code — use controller possession instead.
Signature
APawn* GetPawn() const { return PawnPrivate; } Return Type
APawn* Example
Apply a round-start buff to a player's pawn from game mode logic C++
void AMyGameMode::ApplyRoundStartBuff(APlayerState* PS)
{
if (AMyCharacter* Char = PS->GetPawn<AMyCharacter>())
{
Char->ApplyBuff(EBuffType::RoundStart);
}
// If GetPawn() returns null the player is spectating or not yet spawned
} Tags
Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?