RealDocs

AActor::GetNetOwningPlayer

function Engine Since 4.0
#include "GameFramework/Actor.h"
Access: public Specifiers: virtualENGINE_API

Description

Returns the owning UPlayer for this actor, but only when the actor's role is ROLE_Authority. Returns a local player, a net connection, or nullptr.

Caveats & Gotchas

  • Only returns a valid UPlayer when HasAuthority() is true — calling this on a simulated proxy will return nullptr even if the actor is owned by a player.
  • The distinction from GetNetOwningPlayerAnyRole() is important for server code: use this when you want to avoid accidentally treating client-side simulations as if they have an owning player.
  • A returned UPlayer may be either a ULocalPlayer (listen server/standalone) or a UNetConnection (dedicated server) — cast carefully before using player-specific APIs.

Signature

ENGINE_API virtual class UPlayer* GetNetOwningPlayer()

Return Type

class UPlayer*

Example

Get the owning player on the server C++
if (HasAuthority())
{
    UPlayer* OwningPlayer = GetNetOwningPlayer();
    if (UNetConnection* Conn = Cast<UNetConnection>(OwningPlayer))
    {
        // Actor is owned by a remote client connection
    }
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.