Class 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.
Namespace: Unity.Netcode
Syntax
public class NetworkPrefabHandler
Methods
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
Type | Name | Description |
---|---|---|
UInt32 | globalObjectIdHash | the Unity.Netcode.NetworkObject.GlobalObjectIdHash value of the network prefab asset being overridden |
INetworkPrefabInstanceHandler | instanceHandler | a class that implements the INetworkPrefabInstanceHandler interface |
Returns
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
NetworkObject | prefabAssetNetworkObject | the NetworkObject of the network prefab asset to be overridden |
INetworkPrefabInstanceHandler | instanceHandler | the class that implements the INetworkPrefabInstanceHandler interface to be registered |
Returns
Type | Description |
---|---|
Boolean |
AddHandler(GameObject, INetworkPrefabInstanceHandler)
Use a GameObject to register a class that implements the INetworkPrefabInstanceHandler interface with the NetworkPrefabHandler
Declaration
public bool AddHandler(GameObject networkPrefabAsset, INetworkPrefabInstanceHandler instanceHandler)
Parameters
Type | Name | Description |
---|---|---|
GameObject | networkPrefabAsset | the GameObject of the network prefab asset to be overridden |
INetworkPrefabInstanceHandler | instanceHandler | class that implements the INetworkPrefabInstanceHandler interface to be registered |
Returns
Type | Description |
---|---|
Boolean | true (registered) false (failed to register) |
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 GameObject target overrides that have the NetworkObject component.
Declaration
public void RegisterHostGlobalObjectIdHashValues(GameObject sourceNetworkPrefab, List<GameObject> networkPrefabOverrides)
Parameters
Type | Name | Description |
---|---|---|
GameObject | sourceNetworkPrefab | source NetworkPrefab to be overridden |
List<GameObject> | networkPrefabOverrides | one or more NetworkPrefabs could be used to override the source NetworkPrefab |
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
Type | Name | Description |
---|---|---|
UInt32 | globalObjectIdHash | Unity.Netcode.NetworkObject.GlobalObjectIdHash of the source NetworkPrefab that was being overridden |
Returns
Type | Description |
---|---|
Boolean | true (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
Type | Name | Description |
---|---|---|
NetworkObject | networkObject | NetworkObject of the source NetworkPrefab that was being overridden |
Returns
Type | Description |
---|---|
Boolean | true (success) or false (failure) |
RemoveHandler(GameObject)
Use the GameObject of the overridden network prefab asset to remove a registered class that implements the INetworkPrefabInstanceHandler interface.
Declaration
public bool RemoveHandler(GameObject networkPrefabAsset)
Parameters
Type | Name | Description |
---|---|---|
GameObject | networkPrefabAsset | GameObject of the network prefab asset that was being overridden |
Returns
Type | Description |
---|---|
Boolean | true (success) or false (failure) |