Network Variables
General:
ObjectNet provides the facility to keep variables synchronized over the network.
Those variables are automatically synchronized over the network from Active to Passive instances.
To implement Network Variables, the script must be inherited from NetworkBehaviour
Network variables can synchronize the following types:
int uint long ulong short ushort float double
-------------------------------------------------------------
byte sbyte byte[] bool string char char[] enum
-------------------------------------------------------------
Vector2 Vector3 Vector4 Quaternion Color Matrix4x4can be used in two ways.
By NetworkPrefabs ( see Script Variables )
By Code

Network Variables by code:
To use Network Variable in code they must bound a type NetworkVariable<T> where T must be included into allowed types.
Once defined you can use it as if any other script variable
This provides greater control and access to various callbacks you can leverage. Below are some examples:
Detecting Changes
You can detect when the object was updated on the passive instance to apply changes only when occur.
Note: This will only be triggered on passive object
Important: Modifying the value of a NetworkVariable directly on a passive object can disrupt its internal synchronization logic.
This may prevent the OnValueChanged callback from being triggered in the future—even when a new value is received from the active owner. *unless you used variable.SetValue()
Synchronizing local variables
ObjectNet allows to synchronization of network variables with local variables automatically. The following script allows you to keep a local variable synchronized with a network variable, no matter where you change the value, both variables will have the same value.
Important: Never modify the value of a networked variable on a passive object, especially if it uses Reliable DeliveryMode. This can interfere with the value sent from the active source and cause players to see different results (desync).
Variables DeliveryModes:
there are two Modes NetworkVariables uses Reliable and Unreliable Delivery Mode.
Reliable variables send data only when it detects changes or when a new client join, This makes them ideal for data that changes infrequently, as they reduce bandwidth usage and ensure consistency.
Avoid using Reliable mode for variables that change frequently (e.g., more than once per second), as it may overwhelm the network and introduce latency.
Examples of Reliable variables:
Health, Player name / username, Score / Points, Kill / death count (K/D), Game state (Win/Loss, Start Match, Pause), Quest or mission updates, Timers, lobby settings, Inventory items, map selection, Skins selection, Environmenatl states (e.g., doors open) , etc...
By defalue all NetworkVaraibles will be using Reliable DelivaryMode
Unreliable variables are sent At a constant rate through the network object’s update loop, Using a lightweight, unreliable buffer, making it fast for frequently changing variables (more than once per second constantly).
Unreliable variable could arrive out of order or not at all, making it bad for timers and critical game events
Examples of Unreliable variables:
Input, Position , Target Position, Rotation, Animation parameters, Aim direction / camera look
Change Delievry Mode from Prefab Database
You can change the Network Variable Delivary Mode from the Network Manager Prefab DataBase as shown in the second Image


Change Delievry Mode in code
You can change the Network variable Delivary Mode from Reliable to Unreliable through code
Note: You should only change Delivary Mode in Awake() changing it mid game may cause unexpected behavoiur
Changes Detection Mode (In Reliable Variables)
🛠️ Automatic Detection Mode
By default, all Reliable Variablesin ObjectNet use Automatic Detection Mode. In this mode, ObjectNet continuously monitors variable changes and efficiently packs all detected changes into a single buffer, reducing bandwidth usage and improving performance.

The detection rate is tied to the Object send rate, ensuring that:
Only variables with actual changes are included in the update buffer.
If no changes occur, no network packets are sent, optimizing traffic flow.
🛠️ Manual Detection Mode
When you mark a variable as Manual Detection, ObjectNet will not sync it automatically. The developer take full responsibility for sending these reliable variables by themself.
To send all Manual Reliable variables across all objects use:
This method does not immediately send variable data. It simply Invalidate all variables, allowing them to be detected and included in the next regular send cycle.
📝 Note:
If you are using Warpped Variables you can force an individual variable to be included in the next synchronization cycle by calling:
This manually flags the variable as changed, ensuring it is sent even if its value hasn't been modified.
FAQ:
What if I want to modify a variable from a passive object?
You cannot directly modify a variable on a passive object, as the change will not be synced across other clients. To update the value correctly, you should send an RPC to the active object and let it handle the modification. This ensures that the update is properly synced for everyone.
💡 Even passive objects can call NetworkExecute, but the logic inside will only run on the active side — keeping everything in sync.
Last updated