APlayerState::GetPlayerController
#include "GameFramework/PlayerState.h"
Access: public
Specifiers: UFUNCTIONBlueprintCallableENGINE_API
Description
Returns the player controller that created this player state, or null for remote clients. Use this to reach the owning controller from gameplay code that only has a reference to the PlayerState.
Caveats & Gotchas
- • Returns null on remote clients — the controller only exists on the server and on the local machine for the owning player. Always null-check before dereferencing.
- • For AI-controlled pawns, this returns null even on the server because AIControllers do not use APlayerController. Use GetOwningController() if you need to handle both cases.
Signature
ENGINE_API class APlayerController* GetPlayerController() const; Return Type
APlayerController* Example
Check authority before accessing controller C++
void AMyPlayerState::NotifyPlayerOfEvent()
{
if (APlayerController* PC = GetPlayerController())
{
// Safe: we're on server or this is the local player
PC->ClientShowMessage(FText::FromString(TEXT("Event occurred!")));
}
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?