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

fix: Parented in-scene objects under dynamically spawned objects are destroyed when the network session ends but original scene remains loaded. [MTT-7560] #2737

Merged

Conversation

NoelStephensUnity
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity commented Oct 11, 2023

(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

  • Fixed: Issue where a parented in-scene placed NetworkObject would be destroyed upon a client or server exiting a network session but not unloading the original scene in which the NetworkObject was placed.

Testing and Documentation

  • Includes updated integration test SceneObjectsNotDestroyedOnShutdownTest.SceneObjectsNotDestroyedOnShutdown.
  • Includes new integration test SceneObjectsNotDestroyedOnShutdownTest.ChildSceneObjectsDoNotDestroyOnShutdown.
  • No documentation updates required.

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.
updating the test to reflect the updated error message when a client attempts to destroy a spawned NetworkObject while still connected to a session.
@NoelStephensUnity NoelStephensUnity changed the title fix: parented in scene objects destroyed when network session ends but original scene remains loaded [MTT-7560] fix: Parented in-scene objects under dynamically spawned objects are destroyed when the network session ends but original scene remains loaded. [MTT-7560] Oct 11, 2023
Updating the scene objects not destroyed test.
Adjusting the parenting rules slightly to only deny parenting if the child or parent is not spawned.
Adding `ChildSceneObjectsDoNotDestroyOnShutdown`
removing one of the logical checks that was not required.
Adding ChildSceneObjectsDoNotDestroyOnShutdown test to validate this PR.
Updating ParentedNetworkTransformTest to provide enough time to let interpolation to finish.
@NoelStephensUnity NoelStephensUnity marked this pull request as ready for review October 12, 2023 20:57
@NoelStephensUnity NoelStephensUnity requested a review from a team as a code owner October 12, 2023 20:57
Just touching up one of the comments.
@NoelStephensUnity NoelStephensUnity enabled auto-merge (squash) October 12, 2023 21:55
// - 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))
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice XOR usage suggestion!

Copy link
Collaborator

@ShadauxCat ShadauxCat left a 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.

@NoelStephensUnity NoelStephensUnity merged commit 7ab9947 into develop Nov 28, 2023
23 checks passed
@NoelStephensUnity NoelStephensUnity deleted the fix/child-in-scene-objects-destroyed-client-side branch November 28, 2023 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants