Skip to content
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

AOI issue - NetworkClient.DestroyObject vs NetworkIdentity.OnDestroy #3785

Open
joshbayley opened this issue Mar 19, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@joshbayley
Copy link

joshbayley commented Mar 19, 2024

We have a custom AOI implementation so it might not be a problem by default if handled appropriately there, but we have an issue where client net ids are removed from NetworkClient.spawned AFTER moving out and back into AOI very quickly. This is happening because you're using GameObject.Destroy here:

GameObject.Destroy(identity.gameObject);

but you added a fix re scene loading to NetworkIdentity.OnDestroy here:

NetworkClient.spawned.Remove(netId);

If you're very quick you can have the OnDestroy land after respawning the object and you end up with an orphaned clone.

Fix for us seems to be just using DestroyImmediate but I'm not sure if this has any implications for features we're not using.

NOTE - apologies we're not on latest so you may have fixed this by other means, I'll test on latest shortly.

All the best

@imerr
Copy link
Contributor

imerr commented Mar 19, 2024

Just to make sure I understood this correctly, your AOI can spawn/despawn objects rapidly, and sometimes that causes those objects to be left behind on the client?
Could you check instead of the plain spawned.Remove in NetworkIdentity, adding a check beforehand fixes this?
Something like:

                // make sure to only remove if we are the NI in spawned for netId
                if (NetworkClient.spawned.TryGetValue(netId, out NetworkIdentity id) && id == this)
                {
                    // if an identity is still in .spawned, remove it too.
                    // fixes: https://github.com/MirrorNetworking/Mirror/issues/3324
                    NetworkClient.spawned.Remove(netId);
                }

@miwarnec miwarnec added the bug Something isn't working label Mar 19, 2024
@miwarnec
Copy link
Collaborator

also, any chance that we can reproduce this with one of the mirror demos?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants