🐾PurrNet Docs
Core

Ownership

Ownership determines which client has authority to drive a networked object. PurrNet supports per-component ownership — different components on the same GameObject can have different owners.

Click a player to transfer ownershipGiveOwnership(playerID)
ServerAlways AuthPlayer 1👑Player 2Player 3Owner: Player 1 · Server always retains authority

Ownership vs Authority

Ownership is about identity — which player "owns" the object. Authority is about who can act — who can write SyncVars, call RPCs, etc. The server always has authority. An owner has authority over objects they own (depending on Network Rules).

A common setup: the server spawns a player prefab and immediately gives ownership to the connecting client. That client can then move the character (owner authority) while the server validates all combat (server authority).

API Reference

ParameterTypeDefaultDescription
networkIdentity.isOwnerbool—True on the client that currently owns this identity. False on all other clients and the server.
networkIdentity.isServerbool—True only when this code runs on the server.
networkIdentity.IsControllerbool—True if you are the owner, or if you are the server and no owner is assigned. Useful for authority checks.
networkIdentity.ownerPlayerID?—Nullable PlayerID of the current owner. Null if the object is unowned.
GiveOwnership(PlayerID)void—Transfer ownership to another player. Callable from server-side or the current owner depending on Network Rules.

Lifecycle Callbacks

PlayerController.cs
using PurrNet;

public class PlayerController : NetworkBehaviour
{
    protected override void OnSpawned(bool asServer)
    {
        // asServer=true when running on server, false on clients
        if (isOwner)
        {
            // Enable input, local camera, UI
            EnablePlayerInput();
            CameraRig.Follow(transform);
        }
    }

    protected override void OnOwnerChanged(PlayerID? oldOwner, PlayerID? newOwner)
    {
        // Fires on all clients when ownership transfers
        bool iAmNewOwner = newOwner.HasValue && newOwner.Value == localPlayer;
        EnablePlayerInput(iAmNewOwner);
    }

    protected override void OnOwnerDisconnected()
    {
        // Called when the owner disconnects
        // Server can re-assign or destroy the object
        if (isServer) Destroy(gameObject);
    }

    protected override void OnDespawned()
    {
        // Cleanup before destruction
        CameraRig.Unfollow(transform);
    }
}

Giving and Transferring Ownership

SpawnManager.cs
public class SpawnManager : NetworkBehaviour
{
    [SerializeField] private GameObject playerPrefab;

    // Server-side: spawn a player object and give it to the connecting client
    public void SpawnPlayer(PlayerID player)
    {
        if (!isServer) return;

        var go = Instantiate(playerPrefab, GetSpawnPoint(), Quaternion.identity);
        var identity = go.GetComponent<NetworkIdentity>();

        // Give ownership immediately after spawning
        identity.GiveOwnership(player);
    }

    // Transfer ownership (e.g., trading an item)
    [ServerRpc(requireOwnership: false)]
    public void CmdTransferVehicle(NetworkIdentity vehicle, PlayerID newDriver, RPCInfo info = default)
    {
        // Only current owner or server can transfer
        if (vehicle.owner != info.sender && !info.asServer) return;
        vehicle.GiveOwnership(newDriver);
    }
}

Per-Component Ownership

A single GameObject can carry multiple NetworkIdentity components, each with a different owner. This is useful for shared vehicles where the driver owns the steering component and the gunner owns the turret.

Tank.cs
// Tank GameObject has two NetworkIdentity components:
// [0] TankHull — owned by driver
// [1] TankTurret — owned by gunner

public class TankHull : NetworkBehaviour
{
    // Only the driver (owner) drives
    void Update()
    {
        if (!isOwner) return;
        CmdDrive(Input.GetAxis("Vertical"), Input.GetAxis("Horizontal"));
    }
}

public class TankTurret : NetworkBehaviour
{
    // Only the gunner (owner) aims and fires
    void Update()
    {
        if (!isOwner) return;
        CmdAim(GetMouseAimDirection());
        if (Input.GetButtonDown("Fire1")) CmdFire();
    }
}

IsController shortcut

Use IsController instead of isOwner || isServer — it returns true if you are the owner, or if you are the server and the object has no owner. Covers both server-controlled NPCs and client-controlled players with a single check.

GiveOwnership works server-side

Call GiveOwnership from server code only (inside if (isServer)) unless your Network Rules explicitly permit client-initiated ownership transfers. Unrestricted ownership transfer is a common cheat vector.