-
Notifications
You must be signed in to change notification settings - Fork 450
fix: client owned NetworkObject with prefabhandler destroy order incorrect on host-server side (Backport) #3202
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
{ | ||
var ownedObject = clientOwnedObjects[i]; | ||
if (ownedObject != null) | ||
if (!ownedObject.DontDestroyWithOwner) |
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 a thought, this is a lot of nested ifs. What are your thoughts on nested ifs vs early exits in this type of Netcode context?
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.
Well, I wouldn't exit early because there is other code that needs to run but I did change this to check if it is null and if so then it just continues.
Nesting doesn't bother me personally and in the end the op codes generated are pretty much identical where it ends up jumping back to the top and grabbing the next element (continue) or returning from the method (exit early).
However, it did remove one layer of a nested if which can be easier to read for users...so that is a good catch.
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.
Oh, does the backport need a CHANGELOG entry?
Yes indeed it did. Thanks for the reminder. It is pushed. |
This is a back-port of #3200
Replication of the issue is as follows:
NGO V1: On the host/server side, the Destroy method is called prior to the OnNetworkDespawn.
This also includes:
NetworkObject.InstantiateAndSpawn
.NetworkObject.InstantiateAndSpawn
.NetworkPrefabOverrideTests
was backported from v2.fix: #3190
Changelog
Fixed: Issue where a spawned
NetworkObject
that was registered with a prefab handler and owned by a client would invoke destroy more than once on the host-server side if the client disconnected while theNetworkObject
was still spawned.Fixed: Issue where
NetworkObject.InstantiateAndSpawn
would not honor theisPlayerObject
parameter.Fixed: Issue where
NetworkObject.InstantiateAndSpawn
would not make an instance of a network prefab but would spawn the network prefab itself.Testing and Documentation
NetworkPrefabOverrideTests
.