NetworkObject
It is one of the most important components of the VIROO Networking System. This component assigns a unique identifier to the GameObjects to which it is added. In network synchronized environments it is very important that objects are uniquely identified and that all clients have those objects identified with the same id in all their instances, so that when an interaction is made on an object, all clients know how to interpret that interaction on the same element.
This component is also responsible for storing the information that refers to who has authority over an object.
A NetworkObject acts for all the NetworkBehaviour that are at the same level as it, or those that are nested in GameObjects within it.
Tip
The NetworkObject component is only necessary if the object requires interaction, movement or any kind of synchronization.
NetworkObject | |
---|---|
Field | Description |
Object Id | The field that uniquely identifies this GameObject to all users. |
Authority | This is a read-only field that indicates, if checked, that the local user has the authority over this GameObject. |
Note
GameObjects with nested NetworkObjects is not allowed in VIROO. If a GameObject has this component, none of its children must have it.
Object Id
As we have already mentioned, it is very important that the ObjectId field is unique. This is easily generated using the Generate Object Id
button.
If an GameObject is duplicated and a new ObjectId is not generated in the duplicated object, it will have two objects with the same id and the system will show an error log in the console.
Authority
Authority is important in networked systems. In server authoritative networking systems, the server has authority over the objects and decides how they behave and if a client wants to make a change to one of these, it needs to do it through the server.
In VIROO the authority system is a bit different as a client can request authority over an object and, from that moment, it can modify its behaviour without restrictions.
Sometimes there are certain behaviours that we want only one client to perform, and it is in these cases where the authority can help us decide who does it.
For example, a very common problem is the simulation of the physics, if all the clients simulate the physics in local we find that there can be inconsistencies in the simulation, that is why it is recommended that only one client simulates the physics and transmits the information to the rest.
In VIROO the authority can be requested by code, we have the component NetworkAuthorityEnsurer to manage the authority of the NetworkObject automatically. You have more information about this component here.