-
Notifications
You must be signed in to change notification settings - Fork 450
fix: CleanDiffedSceneObjects was not clearing PendingSoftSyncObjects #834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking at the code above, shouldn't we just iterate over PendingSoftSyncObjects
, call UnityEngine.Object.Destroy
on them and then do PendingSoftSyncObjects.Clear()
?
I think we don't need networkObjectsToDestroy
at all.
I'd suggest something like this (pseudo-code):
// Clean up any in-scene objects that had been destroyed
if (PendingSoftSyncObjects.Count > 0)
{
foreach (var pair in PendingSoftSyncObjects)
{
UnityEngine.Object.Destroy(pair.Value.gameObject);
}
// Make sure to clear this once done destroying all remaining NetworkObjects
PendingSoftSyncObjects.Clear();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that should work since it doesn't modify the actual dictionary but just makes the ghost Unity References null. Either approach works, this one being cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just applied your suggested fix @MFatihMAR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great changes 👌🏻
…player-object-get * develop: test: manual connection approval to fully automated connection approval testing (#839) test: manual rpc tests to automated fixed revision (#841) fix: CleanDiffedSceneObjects was not clearing PendingSoftSyncObjects (#834) feat: NetworkTransform now uses NetworkVariables instead of RPCs (#826) fix: gracefully handle exceptions in an RPC invoke (#846) fix: Fixing utp license file for legal (#843) ci: enable standards check on UTP too (#837) refactor: NetworkBehaviour.NetworkObject no longer throws an exception (#838) fix: revert #830 (#840) test: converting the manual rpc tests over to an automated unit test (#830) # Conflicts: # com.unity.multiplayer.mlapi/Tests/Runtime/MultiInstance/MultiInstanceHelpers.cs
Fix is based on MTT-772:
NetworkSpawnManager.CleanDiffedSceneObjects
was cleaning remaining references to destroyed in-scene placed objects (which is detected and stored within thePendingSoftSyncObjects
dictionary), but it was never clearing thePendingSoftSyncObjects
dictionary which would result in a "key value already exists" error under the following conditions:NetworkObjects
of which some of these in-scene placedNetworkObjects
are destroyed during game play in Scene-B. Then the players transition away from Scene-B to Scene-C (post game scene because the players died or the like).NetworkObjects
destroyed are being re-synchronized but thePendingSoftSyncObjects
still has the sameNetworkInstanceId
as a key and its value would be null because