Network Views
Network Views are the vehicle used to share data across the network. They allow two kinds of network communication: State Synchronization and Remote Procedure Calls.
When you have many clients running the same game, each client has a set of objects which all together make up the game itself. To make two or more clients seem identical, these objects need to be synchronized by sharing data. This is called State Synchronization. Synchronizing the state of every object in the game requires a massive amount of data, easily too much data to be practically sent across the network and keep your game playable. To address this, Network Views are used to specify what data will be shared, and therefore which objects will be synchronized. Each Network View watches a specific part of an object and makes sure it is synchronized with the same object on other clients. More information about State Synchronization can be found on the State Synchronization page.
There are other network scenarios like when you want to send out the position of an object or respawn an item for someone to pick up. Because these are one-time, infrequent operations, it does not make sense to synchronize the state of the involved objects. Instead, you use a Remote Procedure Call to tell the clients or server to perform an operation. More information about Remote Procedure Calls can be found on the RPC Details page.
Technical Details
Network Views are identified across the Network by NetworkViewID's. A NetworkViewID is basically a unique identifier of an object that all networked machines agree on. It is implemented as a 128 bit number but is automatically compressed down to 16 bit when transferred over the network where possible.
Each packet that arrives on the client side needs to be applied to a specific Network View. The NetworkViewID uniquely identifies to which Network View it belongs. Using the NetworkViewID, Unity can find the right Network View, unpack the data and finally apply the incoming packet to the Network View's observed object.
More details about using Network Views in the Editor can be found on the Network View Component Reference page.
If you use Network.Instantiate() to create your Networked objects, you do not need to worry about allocating Network Views and assigning them yourself appropriately. It will all work automatically under the hood.
However, you can manually control the NetworkViewIDs of each Network View by using Network.AllocateViewID. The Scripting Reference documentation shows an example of how an object can be manually instantiated on every client with an RPC function and then the NetworkViewID manually set with AllocateViewID``.
Page last updated: 2007-10-04