ObjectHidemessage is sent to clients when a game object becomes no longer network-visible. By default, Mirror destroys the game object when it receives this message. When a game object becomes visible, the client receives an
ObjectSpawnmessage, as if Mirror has spawned the game object for the first time. By default, the game object is instantiated like any other spawned game object.
NetworkVisibilityon game objects that change visibility state on the host.
OnSetLocalVisibilitydisables or enables all renderer components on the game object. If you want to customize this implementation, you can override the method in your script, and provide a new behavior for how the host (and therefore the local client) should respond when a game object becomes network-visible or invisible (such as disabling HUD elements or renderers).
NetworkIdentitykeeps track of the set of players that it is visible to. The players that a NetworkIdentity game object is visible to are called the “observers” of the NetworkIdentity.
RebuildObserversmethod on the Network Identity component at a fixed interval (set using the “Vis Update Interval” value in the inspector), so that the set of network-visible game objects for each player is updated as they move around.
NetworkVisibilityclass (which your custom observer scripts inherit from), there are some virtual functions for determining visibility. These are:
Physics.OverlapSphereNonAllocto find the players that are within the visibility distance for this object.
RebuildObserversis invoked. This method expects the set of observers to be populated with the players that can see the object. The NetworkServer then handles sending
ObjectSpawnmessages based on the differences between the old and new visibility sets.
NetworkIdentityhas a valid connectionToClient. For example: