Skip to main content

Unity.Netcode.NetworkPrefabHandler

Primary handler to add or remove customized spawn and destroy handlers for a network prefab (i.e. a prefab with a NetworkObject component) Register custom prefab handlers by implementing the INetworkPrefabInstanceHandler interface.

Inheritance#

System.Dynamic.ExpandoObject

System.Dynamic.ExpandoObject

Inherited Members#

Object.Equals(Object)

Object.Equals(Object, Object)

Object.GetHashCode()

Object.GetType()

Object.MemberwiseClone()

Object.ReferenceEquals(Object, Object)

Object.ToString()

Namespace: System.Dynamic.ExpandoObject#
Assembly: MLAPI.dll#
Syntax#
public class NetworkPrefabHandler

AddHandler(GameObject, INetworkPrefabInstanceHandler)#

Use a to register a class that implements the INetworkPrefabInstanceHandler interface with the NetworkPrefabHandler

Declaration#

public bool AddHandler(GameObject networkPrefabAsset, INetworkPrefabInstanceHandler instanceHandler)

Parameters#

TypeNameDescription
GameObjectnetworkPrefabAssetthe of the network prefab asset to be overridden
INetworkPrefabInstanceHandlerinstanceHandlerclass that implements the INetworkPrefabInstanceHandler interface to be registered

Returns#

TypeDescription
System.Booleantrue (registered) false (failed to register)

AddHandler(UInt32, INetworkPrefabInstanceHandler)#

Use a Unity.Netcode.NetworkObject.GlobalObjectIdHash to register a class that implements the INetworkPrefabInstanceHandler interface with the NetworkPrefabHandler

Declaration#

public bool AddHandler(uint globalObjectIdHash, INetworkPrefabInstanceHandler instanceHandler)

Parameters#

TypeNameDescription
System.UInt32globalObjectIdHashthe Unity.Netcode.NetworkObject.GlobalObjectIdHash value of the network prefab asset being overridden
INetworkPrefabInstanceHandlerinstanceHandlera class that implements the INetworkPrefabInstanceHandler interface

Returns#

TypeDescription
System.Boolean

AddHandler(NetworkObject, INetworkPrefabInstanceHandler)#

Use a NetworkObject to register a class that implements the INetworkPrefabInstanceHandler interface with the NetworkPrefabHandler

Declaration#

public bool AddHandler(NetworkObject prefabAssetNetworkObject, INetworkPrefabInstanceHandler instanceHandler)

Parameters#

TypeNameDescription
NetworkObjectprefabAssetNetworkObjectthe NetworkObject of the network prefab asset to be overridden
INetworkPrefabInstanceHandlerinstanceHandlerthe class that implements the INetworkPrefabInstanceHandler interface to be registered

Returns#

TypeDescription
System.Boolean

RegisterHostGlobalObjectIdHashValues(GameObject, List\<GameObject>)#

HOST ONLY! Since a host is unique and is considered both a client and a server, for each source NetworkPrefab you must manually register all potential target overrides that have the NetworkObject component.

Declaration#

public void RegisterHostGlobalObjectIdHashValues(GameObject sourceNetworkPrefab, List<GameObject> networkPrefabOverrides)

Parameters#

TypeNameDescription
GameObjectsourceNetworkPrefabsource NetworkPrefab to be overridden
System.Collections.Generic.List\<GameObject>networkPrefabOverridesone or more NetworkPrefabs could be used to override the source NetworkPrefab

RemoveHandler(GameObject)#

Use the of the overridden network prefab asset to remove a registered class that implements the INetworkPrefabInstanceHandler interface.

Declaration#

public bool RemoveHandler(GameObject networkPrefabAsset)

Parameters#

TypeNameDescription
GameObjectnetworkPrefabAssetof the network prefab asset that was being overridden

Returns#

TypeDescription
System.Booleantrue (success) or false (failure)

RemoveHandler(UInt32)#

Use the Unity.Netcode.NetworkObject.GlobalObjectIdHash of the overridden network prefab asset to remove a registered class that implements the INetworkPrefabInstanceHandler interface.

Declaration#

public bool RemoveHandler(uint globalObjectIdHash)

Parameters#

TypeNameDescription
System.UInt32globalObjectIdHashUnity.Netcode.NetworkObject.GlobalObjectIdHash of the source NetworkPrefab that was being overridden

Returns#

TypeDescription
System.Booleantrue (success) or false (failure)

RemoveHandler(NetworkObject)#

Use the NetworkObject of the overridden network prefab asset to remove a registered class that implements the INetworkPrefabInstanceHandler interface.

Declaration#

public bool RemoveHandler(NetworkObject networkObject)

Parameters#

TypeNameDescription
NetworkObjectnetworkObjectNetworkObject of the source NetworkPrefab that was being overridden

Returns#

TypeDescription
System.Booleantrue (success) or false (failure)