APlayerController::GetPawn
#include "GameFramework/Controller.h"
Access: public
Specifiers: inline
Description
Returns the pawn currently possessed by this controller, or `nullptr` if no pawn is possessed. The template parameter lets you skip an explicit `Cast<T>` at the call site. The Blueprint-exposed equivalent is `K2_GetPawn()` / the "Get Controlled Pawn" node.
Signature
template<class T = APawn> T* GetPawn() const Return Type
T* Caveats & Gotchas
- • Returns `nullptr` during spectating — use `GetPawnOrSpectator()` if you need a non-null pawn-like actor in that state.
- • Prefer calling this after possession has occurred rather than in the controller's own `BeginPlay`, where the pawn may not yet be assigned.
Example
Typed access without explicit cast C++
AMyCharacter* MyChar = GetPawn<AMyCharacter>();
if (MyChar) { MyChar->DoSomething(); } Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
| 5.0 | stable | — |
Feedback
Was this helpful?