Version: 2018.3 (switch to 2019.1)
  • C#
Method group is Obsolete


Suggest a change


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.


Submission failed

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



Obsolete public static void RegisterPrefab(GameObject prefab);
Obsolete public static void RegisterPrefab(GameObject prefab, Networking.SpawnDelegate spawnHandler, Networking.UnSpawnDelegate unspawnHandler);
Obsolete public static void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId);


prefabA Prefab that will be spawned.
spawnHandlerA method to use as a custom spawnhandler on clients.
unspawnHandlerA method to use as a custom un-spawnhandler on clients.
newAssetIdAn assetId to be assigned to this Prefab. This allows a dynamically created game object to be registered for an already known asset Id.


Registers a Prefab with the UNET spawning system.

When a NetworkIdentity object is spawned on a server with NetworkServer.SpawnObject(), and the Prefab that the object was created from was registered with RegisterPrefab(), the client will use that Prefab to instantiate a corresponding client object with the same netId.

The NetworkManager has a list of spawnable Prefabs, it uses this function to register those Prefabs with the ClientScene.

The set of current spawnable object is available in the ClientScene static member variable ClientScene.prefabs, which is a dictionary of NetworkAssetIds and Prefab references.

using UnityEngine;
using UnityEngine.Networking;

public class PlantSpawner : NetworkBehaviour { public GameObject plantPrefab;

public override void OnStartClient() { ClientScene.RegisterPrefab(plantPrefab); }

[Server] public void ServerSpawnPlant(Vector3 pos, Quaternion rot) { var plant = (GameObject)Instantiate(plantPrefab, pos, rot); NetworkServer.Spawn(plant); } }

The optional custom spawn and un-spawn handler functions can be used to implement more advanced spawning strategies such as object pools.

Did you find this page useful? Please give it a rating: