Common Functions

Below are some commonly used methods available within the NetworkBehaviour class that can assist with implementing multiplayer logic.

GetNetworkId()

Each NetworkObject has its unique id thats how ObjectNet diffrentiate between diffrent objects on the scene.

int id = this.GetNetworkId();
HasNetworkElement()

Check wheather the NetworkObject is initialized and NetworkElement was created

if(this.HasNetworkElement()){
}
GetNetworkElement()

Returns the INetworkElement associated with the current NetworkObject. This provides access to a broader set of functions that allow you to control and customize the behavior of the networked object.

this.GetNetworkElement()
SetActiveRate()

After retrieving the INetworkElement, you can use it to dynamically adjust the send rate of the associated NetworkObject by calling:

//change active send rate of this network object
GetNetworkElement().SetActiveRate(int rate)
//or change minmum send rate when no changes are detected only for that object
GetNetworkElement().SetMinimunRateValue(int minimumRateValue)
Pause and Resume Behaviours

You can pause and resume Behaviours like Position sync, Animations sync, Variables sync. through code and resume them when ever you want.

 //Pause
this.GetNetworkElement().GetBehavior<PositionNetwork>().Pause();
this.GetNetworkElement().GetBehavior<RotationNetwork>().Pause();
this.GetNetworkElement().GetBehavior<ScaleNetwork>().Pause();
this.GetNetworkElement().GetBehavior<AnimationNetwork>().Pause();
this.GetNetworkElement().GetBehavior<VariablesNetwork>().Pause();
 //Resume
this.GetNetworkElement().GetBehavior<PositionNetwork>().Resume();
this.GetNetworkElement().GetBehavior<RotationNetwork>().Resume();
this.GetNetworkElement().GetBehavior<ScaleNetwork>().Resume();
this.GetNetworkElement().GetBehavior<AnimationNetwork>().Resume();
this.GetNetworkElement().GetBehavior<VariablesNetwork>().Resume();
Teleport()

You can teleport the Networkobject without interpolating it on the passive.

this.Teleport(targetPosition);
IsActive() and IsPassive()

Determines whether the current NetworkObject is Active or Passive (a remote instance). For a detailed explanation of Active vs Passive objects, see Ownership.

if (IsActive()) { 
    // This object is the data owner 
}

if (IsPassive()) { 
    // This object is a remote replica 
}
IsRuningLogic()

This checks if your current device is the Host — the one responsible for running all the authoritative game logic.

Think of this as: "Am I in charge of running the game world?"

this.IsRunningLogic()
IsOwner()

This is useful when useing Remote Controls as all objects will be passive on clients even player object, and the only way for clients to know if they own the player will be by using

if(this.IsOwner()){
}
IsPlayer()

Determines whether the object is a Player GameObject.

if (this.IsPlayer()){
}
TakeControl()

Takes control over the passive object turining it to Active. Check Dynamic Ownership Transfer for more details.

//Call on Passive
TakeControl()

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.

SetBehaviourMode()

The TakeControl() method is used to switch a NetworkObject from Passive to Active mode. However, this process is not instant — it requires approval from the server before the mode change is applied.

If you need to immediately switch a local object to Active mode (e.g., for instant responsiveness), you can do so by calling SetBehaviorMode(BehaviorMode.Active) directly after calling TakeControl(). This updates the local state immediately while still allowing TakeControl() to handle proper server-side ownership and passive transition of the previously active object.

Here’s how to combine both calls for smooth control handoff:

// Notify the server to handle ownership changes
this.TakeControl();

// Instantly switch the local object to Active mode without delay
this.SetBehaviorMode(BehaviorMode.Active, false);
//make sure to set the second parameter detectOnStart to false 
//just as shown in the example above or else it will trigger OnNetworkStart().

These are specific Methods in the NetworkBehaviour class, for a more global methods check Network Manager Common Functions

For a complete list, refer to the API Documentation.

Last updated