Skip to content

fix: Add OnPreShutdown to NetworkManager #3358

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 3 commits into from
Mar 26, 2025
Merged

Conversation

jonathanhertz
Copy link
Contributor

This PR adds a NetworkManager.OnPreShutdown callback that happens before the internal shutdown is done. This is to allow accessing any state that is cleaned up by the NetworkManager during shutdown, such as accessing dynamically spawned NetworkObjects.

fix: #3145
close: #3145

Changelog

  • Added: The event NetworkManager.OnPreShutdown has been added which is called before the NetworkManager cleans up and shuts down.

Testing and Documentation

  • A test has been added to ensure this is being called, and called before OnServerStopped.

@jonathanhertz jonathanhertz requested a review from a team as a code owner March 25, 2025 09:45
@unity-cla-assistant
Copy link

unity-cla-assistant commented Mar 25, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

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

Minor nit-pick on the XML API description, but the rest looks good!

/// Subscribe to this static event to get notifications before a <see cref="NetworkManager"/> instance is being destroyed.
/// This is useful if you want to use the state of anything the NetworkManager cleans up during its shutdown.
/// </summary>
public event Action OnPreShutdown = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor side note, you don't need to set it to null as that is the default value when the NetworkManager class is instantiated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I just figured I'd keep it consistent with the other events.

@NoelStephensUnity NoelStephensUnity added the port:2.x-needed This issue needs to be ported to 2.X branch label Mar 25, 2025
NoelStephensUnity and others added 2 commits March 25, 2025 09:44
Updating this for v1.x since all tests are public.
@jonathanhertz jonathanhertz merged commit d0f73d4 into develop Mar 26, 2025
40 checks passed
@jonathanhertz jonathanhertz deleted the fix/onpreshutdown branch March 26, 2025 13:10
NoelStephensUnity added a commit that referenced this pull request Mar 29, 2025
Forwardport of
#3358

This PR adds a `NetworkManager.OnPreShutdown` callback that happens
before the internal shutdown is done. This is to allow accessing any
state that is cleaned up by the `NetworkManager` during shutdown, such
as accessing dynamically spawned NetworkObjects.

## Changelog

- Added: The event NetworkManager.OnPreShutdown has been added which is
called before the NetworkManager cleans up and shuts down.

## Testing and Documentation

- A test has been added to ensure this is being called, and called
before OnServerStopped.

<!-- Uncomment and mark items off with a * if this PR deprecates any
API:
### Deprecated API
- [ ] An `[Obsolete]` attribute was added along with a `(RemovedAfter
yyyy-mm-dd)` entry.
- [ ] An [api updater] was added.
- [ ] Deprecation of the API is explained in the CHANGELOG.
- [ ] The users can understand why this API was removed and what they
should use instead.
-->

---------

Co-authored-by: Noel Stephens <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
port:2.x-needed This issue needs to be ported to 2.X branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

when quiting, spawned object become null whereas in-scene objects are not.
3 participants