diff --git a/Assets/Mirage/Runtime/ClientObjectManager.cs b/Assets/Mirage/Runtime/ClientObjectManager.cs
index 9055898438..112543415e 100644
--- a/Assets/Mirage/Runtime/ClientObjectManager.cs
+++ b/Assets/Mirage/Runtime/ClientObjectManager.cs
@@ -301,9 +301,10 @@ public void UnregisterPrefab(NetworkIdentity identity)
/// A method to use as a custom un-spawnhandler on clients.
public void RegisterSpawnHandler(NetworkIdentity identity, SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
{
- ThrowIfZeroHash(identity);
var prefabHash = identity.PrefabHash;
- RegisterSpawnHandler(prefabHash, spawnHandler, unspawnHandler);
+ ValidateRegisterSpawnHandler(prefabHash, spawnHandler, unspawnHandler);
+
+ _handlers[prefabHash] = new SpawnHandler(identity, spawnHandler, unspawnHandler);
}
///
@@ -322,9 +323,10 @@ public void RegisterSpawnHandler(int prefabHash, SpawnHandlerDelegate spawnHandl
public void RegisterSpawnHandler(NetworkIdentity identity, SpawnHandlerAsyncDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
{
- ThrowIfZeroHash(identity);
var prefabHash = identity.PrefabHash;
- RegisterSpawnHandler(prefabHash, spawnHandler, unspawnHandler);
+ ValidateRegisterSpawnHandler(prefabHash, spawnHandler, unspawnHandler);
+
+ _handlers[prefabHash] = new SpawnHandler(identity, spawnHandler, unspawnHandler);
}
public void RegisterSpawnHandler(int prefabHash, SpawnHandlerAsyncDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
@@ -784,6 +786,14 @@ public SpawnHandler(SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHa
UnspawnHandler = unspawnHandler;
}
+ public SpawnHandler(NetworkIdentity prefab, SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
+ {
+ Prefab = prefab ?? throw new ArgumentNullException(nameof(prefab));
+ Handler = spawnHandler ?? throw new ArgumentNullException(nameof(spawnHandler));
+ // unspawn is allowed to be null
+ UnspawnHandler = unspawnHandler;
+ }
+
public SpawnHandler(SpawnHandlerAsyncDelegate spawnHandlerAsync, UnSpawnDelegate unspawnHandler)
{
HandlerAsync = spawnHandlerAsync ?? throw new ArgumentNullException(nameof(spawnHandlerAsync));
@@ -791,6 +801,14 @@ public SpawnHandler(SpawnHandlerAsyncDelegate spawnHandlerAsync, UnSpawnDelegate
UnspawnHandler = unspawnHandler;
}
+ public SpawnHandler(NetworkIdentity prefab, SpawnHandlerAsyncDelegate spawnHandlerAsync, UnSpawnDelegate unspawnHandler)
+ {
+ Prefab = prefab ?? throw new ArgumentNullException(nameof(prefab));
+ HandlerAsync = spawnHandlerAsync ?? throw new ArgumentNullException(nameof(spawnHandlerAsync));
+ // unspawn is allowed to be null
+ UnspawnHandler = unspawnHandler;
+ }
+
public void AddUnspawnHandler(UnSpawnDelegate unspawnHandler)
{
if (Prefab == null)