Network ID System
1. Overview
The Network ID System provides a unique identifier for every networked object in HoloMIT, ensuring all clients can reference the exact same objects consistently across the network. It forms the foundation for all networked components.
2. NetworkIdBehaviour (Core Component)
This is the base class for almost all networked components in HoloMIT.
2.1. Properties
Figure 1: The Network ID field in the Unity Inspector.
- NetworkId (string): A unique GUID assigned to the GameObject.
2.2. Automatic Assignment & Editor Integration
In the Editor, a GUID is automatically generated and serialized to prevent manual tracking errors. It uses injected editor callbacks (IsAssetOnDiskFunc, RecordUndoFunc, RecordPrefabModificationsFunc) to ensure that:
- Prefab assets stored on disk do not have pre-generated IDs (avoiding conflicts when instantiating).
- Instances placed in the scene automatically receive unique IDs.
At runtime, the Awake() method ensures the GameObject has a valid network ID, and OnDestroy() removes it from the active manager.
The SetNetworkId() function can be used on remote clients to apply the ID assigned by the spawn initiator instead of relying on the auto-generated local one.
3. NetworkIdManager (Central Registry)
A singleton-like internal manager that maintains a registry of all active NetworkIdBehaviour instances.
3.1. Conflict Detection
If two objects try to register the same ID, the manager prevents desynchronization:
- For local assignment, it recursively generates a new ID.
- For remote assignment (via
SetNetworkId), it logs an error to highlight the collision.
4. NetworkIdAttribute
A custom attribute used to style the Network ID field in the Unity Inspector, making it visually distinct and managing its read-only status when appropriate.