Skip to content

Commit 8ba2043

Browse files
committed
Add PrefabHandler shutdown
1 parent efa756c commit 8ba2043

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,8 +1593,9 @@ internal void ShutdownInternal()
15931593
// Completely reset the NetworkClient
15941594
ConnectionManager.LocalClient = new NetworkClient();
15951595

1596-
// This cleans up the internal prefabs list
1596+
// Clean up the internal prefabs data
15971597
NetworkConfig?.Prefabs?.Shutdown();
1598+
PrefabHandler.Shutdown();
15981599

15991600
// Reset the configuration hash for next session in the event
16001601
// that the prefab list changes

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3247,6 +3247,7 @@ internal static NetworkObject AddSceneObject(in SceneObject sceneObject, FastBuf
32473247
var bufferSerializer = new BufferSerializer<BufferSerializerReader>(new BufferSerializerReader(reader));
32483248
networkObject.SynchronizeNetworkBehaviours(ref bufferSerializer, networkManager.LocalClientId);
32493249

3250+
// Ensure that the buffer is completely reset
32503251
if (reader.Position != endOfSynchronizationData)
32513252
{
32523253
Debug.LogWarning($"[Size mismatch] Expected: {endOfSynchronizationData} Currently At: {reader.Position}!");

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkPrefabHandler.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,27 +283,21 @@ internal uint GetSourceGlobalObjectIdHash(uint networkPrefabHash)
283283
internal NetworkObject HandleNetworkPrefabSpawn(uint networkPrefabAssetHash, ulong ownerClientId, Vector3 position, Quaternion rotation, byte[] instantiationData = null)
284284
{
285285
NetworkObject networkObjectInstance = null;
286-
var needsInstantiation = true;
287286
if (instantiationData != null)
288287
{
289288
if (m_PrefabAssetToPrefabHandlerWithData.TryGetValue(networkPrefabAssetHash, out var prefabInstanceHandler))
290289
{
291-
needsInstantiation = false;
292290
networkObjectInstance = prefabInstanceHandler.Instantiate(ownerClientId, position, rotation, instantiationData);
293291
}
294292
else
295293
{
296294
Debug.LogError($"[InstantiationData] Failed instantiate with data: no compatible data handler found for object hash {networkPrefabAssetHash}. Instantiation data will be dropped.");
295+
return null;
297296
}
298297
}
299-
300-
// Fallback to default handler
301-
if (needsInstantiation)
298+
else if (m_PrefabAssetToPrefabHandler.TryGetValue(networkPrefabAssetHash, out var prefabInstanceHandler))
302299
{
303-
if (m_PrefabAssetToPrefabHandler.TryGetValue(networkPrefabAssetHash, out var prefabInstanceHandler))
304-
{
305-
networkObjectInstance = prefabInstanceHandler.Instantiate(ownerClientId, position, rotation);
306-
}
300+
networkObjectInstance = prefabInstanceHandler.Instantiate(ownerClientId, position, rotation);
307301
}
308302

309303
// Now we must make sure this alternate PrefabAsset spawned in place of the prefab asset with the networkPrefabAssetHash (GlobalObjectIdHash)
@@ -466,5 +460,10 @@ internal void Initialize(NetworkManager networkManager)
466460
{
467461
m_NetworkManager = networkManager;
468462
}
463+
464+
internal void Shutdown()
465+
{
466+
m_PrefabInstanceToPrefabAsset.Clear();
467+
}
469468
}
470469
}

0 commit comments

Comments
 (0)