Legacy Documentation: Version 4.6
Language: English
State Synchronization Details
Network Level Loading

Network Instantiate

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

The Network.Instantiate function offers a straightforward way to instantiate a prefab on all clients, similar to the effect of Object.Instantiate on a single client. The instantiating client is the one that controls the object (ie, the Input class is only accessible from scripts running on the client instance) but changes will be reflected across the network.

The argument list for Network.Instantiate() is as follows:

static function Instantiate (prefab : Object, position : Vector3, rotation : Quaternion, group : int) : Object


As with Object.Instantiate, the first three parameters describe the prefab to be instantiated along with its desired position and rotation. The group parameter allows you to define subgroups of objects to control the filtering of messages and can be set to zero if filtering is not required (see the Communication Groups section below).

Technical Details

Behind the scenes, network instantiation is built around an RPC call which contains an identifier for the prefab along with the position and other details. The RPC call is always buffered in the same manner as other RPC calls, so that instantiated objects will appear on new clients when they connect. See the RPC page for further details about buffering.

Communication Groups

Communication groups can be used to select the clients that will receive particular messages. For example, two connected players might be in separate areas of the game world and may never be able to meet. There is thus no reason to transfer game state between the two player clients but you may still want to allow chat communication between them. In this case, instantiation would need to be restricted for gameplay objects but not for the objects that implement the chat feature and so they would be put in separate groups.

State Synchronization Details
Network Level Loading