Skip to content

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

Merged
merged 5 commits into from
May 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -547,20 +547,16 @@ 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<NetworkObject>();

foreach (var pair in PendingSoftSyncObjects)
{
networkObjectsToDestroy.Add(pair.Value);
UnityEngine.Object.Destroy(pair.Value.gameObject);
}

for (int i = 0; i < networkObjectsToDestroy.Count; i++)
{
UnityEngine.Object.Destroy(networkObjectsToDestroy[i].gameObject);
}
// Make sure to clear this once done destroying all remaining NetworkObjects
PendingSoftSyncObjects.Clear();
Copy link
Contributor

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();
}

Copy link
Contributor

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.

Copy link
Collaborator Author

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

}
}

Expand Down