-
Notifications
You must be signed in to change notification settings - Fork 437
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
fix: Parented in-scene objects under dynamically spawned objects are destroyed when the network session ends but original scene remains loaded. [MTT-7560] #2737
Conversation
Fixes the issue with an in-scene placed NetworkObject being parented under a dynamically spawned NetworkObject and a sudden shutdown/exit occurs. This will remove the child in-scene placed NetworkObject from the parent during the NetworkManager shutdown process where it destroys all dynamically spawned NetworkObjects.
fixing bad changelog merge
// - This instance is not spawned and the parent is. | ||
// Basically, don't allow parenting when either the child or parent is not spawned. | ||
// Caveat: if the parent is null then we can allow parenting whether the instance is or is not spawned. | ||
if (parent != null && (IsSpawned && !parent.IsSpawned || !IsSpawned && parent.IsSpawned)) |
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.
Totally optional comment, BUT... (IsSpawned && !parent.IsSpawned || !IsSpawned && parent.IsSpawned)
could be simplified to IsSpawned ^ parent.IsSpawned
.
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.
Nice XOR usage suggestion!
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.
One small comment, up to you whether you want to change it or not, approved either way.
fixing merge issues
(Discovered using internal modified Client Driven Testing Tool)
In-scene placed NetworkObjects that are parented under dynamically spawned Networkobjects should not be destroyed on the client side (i.e. when the scene is unloaded it will/should be destroyed). Likewise, on the server-host side, if the in-scene placed NetworkObject is marked with "Don't Destroy with Owner" then the server-host should not allow it to be destroyed when shutting down a session (i.e. when the scene is unloaded it will/should be destroyed).
MTT-7560
Changelog
NetworkObject
would be destroyed upon a client or server exiting a network session but not unloading the original scene in which theNetworkObject
was placed.Testing and Documentation
SceneObjectsNotDestroyedOnShutdownTest.SceneObjectsNotDestroyedOnShutdown
.SceneObjectsNotDestroyedOnShutdownTest.ChildSceneObjectsDoNotDestroyOnShutdown
.