APlayerState::GetOwningController
#include "GameFramework/PlayerState.h"
Access: public
Specifiers: ENGINE_API
Description
Returns the AI or player controller that created this player state. Unlike GetPlayerController, this also returns a valid pointer for bot-controlled pawns.
Caveats & Gotchas
- • Returns null on remote clients for all players — the controller relationship only exists on the server and on the local machine for the owning player.
- • The return type is AController, not APlayerController. Always cast before calling player-controller-specific functions. Use GetPlayerController() if you only care about human players.
Signature
ENGINE_API class AController* GetOwningController() const; Return Type
AController* Example
Handle both human and AI controllers C++
void AMyActor::NotifyOwner(APlayerState* PS)
{
if (AController* C = PS->GetOwningController())
{
if (APlayerController* PC = Cast<APlayerController>(C))
{
PC->ClientShowNotification();
}
else if (auto* AIC = Cast<AAIController>(C))
{
// AI controller path
AIC->ReceiveNotification();
}
}
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?