From ec5d255d5f6a7bbd9436167d768e9d5f262aba42 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sat, 15 May 2021 18:40:14 -0500 Subject: [PATCH 1/3] fix MTT-772: Clear PendingSoftSyncObjects in CleanDiffedSceneObjects --- .../Runtime/Spawning/NetworkSpawnManager.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs b/com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs index 31edfcf458..389c4cfb32 100644 --- a/com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs +++ b/com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs @@ -561,6 +561,9 @@ internal void CleanDiffedSceneObjects() { UnityEngine.Object.Destroy(networkObjectsToDestroy[i].gameObject); } + + // Make sure to clear this once done destroying all remaining NetworkObjects + PendingSoftSyncObjects.Clear(); } } From 31747c53e3fa45f2ebcd9d296767cb7f4d35aee9 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sat, 15 May 2021 18:45:07 -0500 Subject: [PATCH 2/3] style improving the comments --- .../Runtime/Spawning/NetworkSpawnManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs b/com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs index 389c4cfb32..d06bc42b28 100644 --- a/com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs +++ b/com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs @@ -547,7 +547,7 @@ internal void DestroySceneObjects() internal void CleanDiffedSceneObjects() { - // Clean up the diffed scene objects. I.E scene objects that have been destroyed + // Clean up any in-scene objects that had been destroyed if (PendingSoftSyncObjects.Count > 0) { var networkObjectsToDestroy = new List(); From 520eac2a2c14286bbc90ac66dc1fc755790c4288 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed, 19 May 2021 18:33:16 -0500 Subject: [PATCH 3/3] refactor Taking Fatih's suggested optimized solution for this fix. --- .../Runtime/Spawning/NetworkSpawnManager.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs b/com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs index 663335a938..ff161eab4a 100644 --- a/com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs +++ b/com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs @@ -550,16 +550,9 @@ internal void CleanDiffedSceneObjects() // Clean up any in-scene objects that had been destroyed if (PendingSoftSyncObjects.Count > 0) { - var networkObjectsToDestroy = new List(); - foreach (var pair in PendingSoftSyncObjects) { - networkObjectsToDestroy.Add(pair.Value); - } - - for (int i = 0; i < networkObjectsToDestroy.Count; i++) - { - UnityEngine.Object.Destroy(networkObjectsToDestroy[i].gameObject); + UnityEngine.Object.Destroy(pair.Value.gameObject); } // Make sure to clear this once done destroying all remaining NetworkObjects