From f67aa64d59052d91b51abfa4c6e90d4541e317ea Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Tue, 29 Nov 2022 06:16:53 -0500 Subject: [PATCH] fix: MatchInterestManagement - use TryGetValue in OnDestroyed --- .../Match/MatchInterestManagement.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Assets/Mirror/Components/InterestManagement/Match/MatchInterestManagement.cs b/Assets/Mirror/Components/InterestManagement/Match/MatchInterestManagement.cs index cda3d5ede..d077bfa6d 100644 --- a/Assets/Mirror/Components/InterestManagement/Match/MatchInterestManagement.cs +++ b/Assets/Mirror/Components/InterestManagement/Match/MatchInterestManagement.cs @@ -43,10 +43,12 @@ public override void OnSpawned(NetworkIdentity identity) public override void OnDestroyed(NetworkIdentity identity) { - lastObjectMatch.TryGetValue(identity, out Guid currentMatch); - lastObjectMatch.Remove(identity); - if (currentMatch != Guid.Empty && matchObjects.TryGetValue(currentMatch, out HashSet objects) && objects.Remove(identity)) - RebuildMatchObservers(currentMatch); + if (lastObjectMatch.TryGetValue(identity, out Guid currentMatch)) + { + lastObjectMatch.Remove(identity); + if (currentMatch != Guid.Empty && matchObjects.TryGetValue(currentMatch, out HashSet objects) && objects.Remove(identity)) + RebuildMatchObservers(currentMatch); + } } // internal so we can update from tests