ObjectHide
message 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 ObjectSpawn
message, 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.NetworkVisibility
on game objects that change visibility state on the host.OnSetLocalVisibility
disables 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).NetworkIdentity
keeps 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.RebuildObservers
method 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.NetworkVisibility
class (which your custom observer scripts inherit from), there are some virtual functions for determining visibility. These are:Physics.OverlapSphereNonAlloc
to find the players that are within the visibility distance for this object.RebuildObservers
is invoked. This method expects the set of observers to be populated with the players that can see the object. The NetworkServer then handles sending ObjectHide
and ObjectSpawn
messages based on the differences between the old and new visibility sets.NetworkIdentity
has a valid connectionToClient. For example: