Ownership

How Ownership and authority works in ObjectNet (Active X Passive)

In ObjectNet, ownership is the cornerstone of how network objects are controlled and synchronized across all clients. Ownership determines which client actively controls an object and how other clients passively interact with it. To provide clarity and ensure smooth gameplay, ObjectNet defines ownership in terms of Active and Passive states.


Active

A client with Active Ownership is responsible for directly controlling the network object. This means:

  • They dictate the object's behavior (e.g., position, actions, animations).

  • They send updates to the network so other clients can stay synchronized.

An object in the Active state is fully controlled by its owner, ensuring minimal latency and the most responsive experience for the controlling player.

Example:

Imagine a multiplayer racing game:

  • Player A owns and drives a car. As the Active Owner, Player A decides the car’s movements (steering, acceleration, braking) and updates the server with the car’s state.

  • Player A's inputs are sent to the server, which then propagates these updates to other players.

You can check if a NetworkObject is in the Active State (meaning you own and control the object) by using isActive().


Passive

All other clients are in a Passive State for objects they do not own. Clients in this state:

  • Cannot control the object directly.

  • Receive updates from the active owner to represent the object accurately on their side.

The passive representation ensures all players can see the object’s latest state (e.g., position, speed, or visual effects) without conflicting with the active owner’s control.

Example:

In the same racing game:

  • Player B and Player C observe Player A's car as it moves around the track.

  • Their clients receive updates from Player A, which synchronize the car’s position, speed, and direction. Player B and Player C display these updates without directly modifying the car’s state

To check if a NetworkObject is in the Passive State (meaning you are not the owner and only receive updates), you can use the isPassive()


Your scripts need to inherit from the NetworkBehaviour class, which is part of the com.onlineobject.objectnet namespace. Read Network Behaviour for more information on this topic.

Code Example
using UnityEngine;
using com.onlineobject.objectnet;

public class OwnerShipExample : NetworkBehaviour
{
    public override void OnNetworkStarted()
    {
        // Check if the object is in the Active State (you own it)
        if(isActive()){ 
            Debug.Log("I have Authority over this object");
            }
        // Check if the object is in the Passive State (you do not own it)
        if(isPassive()){
            Debug.Log("I have no Authority over this object");
        }
    }
}


Dynamic Ownership Transfer

ObjectNet supports dynamic ownership transfer, which is crucial for flexible gameplay scenarios. Ownership can be reassigned between clients as needed:

  • Disconnection: If the active owner disconnects, another client automatically takes over to maintain control of the object.

  • Gameplay Mechanics: Certain scenarios, such as passing a ball in a sports game or handing over an item in a co-op game, may require ownership to be transferred from one client to another dynamically.

Example:

In a multiplayer basketball game:

  • Player A owns the ball and is actively dribbling it. Other players are in the passive state, observing the ball’s movement.

  • When Player A passes the ball to Player B, ownership transfers to Player B. Player B now has Active Ownership, while Player A and others move into the passive state.

you can find it on the NetworkManager gameobject

Code Implementation

You can Take the OwnerShip of a passive NetworkObject using TakeControl() method, it will change the authority state of the NetworkObject from Passive to Active on the Client that calls it, And set it to Passive on all other clients.

//Takes the authority over the NetworkObject
TakeControl();     
//transfere the controls to another player using players Network ID 
TransferControl(int playerNetworkID); 
//returns the control back to the server
ReleaseControl();

Note: TakeControl() will automatically configure the object for Active mode, enabling relevant scripts and setting the Rigidbody accordingly. The previously active instance will also be updated to reflect Passive mode, with its components adjusted as needed.


Why This System Matters

The Active and Passive ownership model in ObjectNet ensures:

  • Responsive Gameplay: The active owner enjoys full control without interference from other clients.

  • Accurate Representation: All other clients see consistent and synchronized object states.

  • Network Efficiency: Passive clients only receive updates, reducing bandwidth usage and avoiding conflicts.

  • Dynamic Flexibility: Ownership can shift dynamically to accommodate gameplay needs, ensuring seamless transitions.

By clearly defining ownership in terms of Active and Passive states, ObjectNet provides a robust framework for managing network objects in multiplayer environments, making it intuitive for developers and efficient for gameplay.

Last updated