-
Notifications
You must be signed in to change notification settings - Fork 459
fix: Shut down NetworkManager when reloading the domain
#4068
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
base: develop-2.0.0
Are you sure you want to change the base?
Changes from 2 commits
5fae671
ee90d32
87da13f
1d76384
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,10 @@ private static void InitializeOnload() | |||||
| Singleton = new NetworkManagerHelper(); | ||||||
|
|
||||||
| NetworkManager.NetworkManagerHelper = Singleton; | ||||||
|
|
||||||
| AssemblyReloadEvents.beforeAssemblyReload -= AssemblyReloadEvents_beforeAssemblyReload; | ||||||
| AssemblyReloadEvents.beforeAssemblyReload += AssemblyReloadEvents_beforeAssemblyReload; | ||||||
|
|
||||||
| EditorApplication.playModeStateChanged -= EditorApplication_playModeStateChanged; | ||||||
| EditorApplication.hierarchyChanged -= EditorApplication_hierarchyChanged; | ||||||
|
|
||||||
|
|
@@ -55,6 +59,23 @@ private static void InitializeOnload() | |||||
| }; | ||||||
| } | ||||||
|
|
||||||
| private static void AssemblyReloadEvents_beforeAssemblyReload() | ||||||
| { | ||||||
| if (Application.isPlaying) | ||||||
| { | ||||||
| #if UNITY_2023_1_OR_NEWER | ||||||
| var networkManager = Object.FindAnyObjectByType<NetworkManager>(); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We added our own static API that hides all the different mutations FindObjects has gone through over time. Though I think rather than searching for all NetworkManagers, it'd be better if any started NetworkManager registers themselves to something so they can be shut down. Objects.FindAll can be slow, I'd rather avoid needing to make Domain reloads any slower.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I modified the code to use |
||||||
| #else | ||||||
| var networkManager = Object.FindObjectOfType<NetworkManager>(); | ||||||
| #endif | ||||||
| if (networkManager != null && (networkManager.IsServer || networkManager.IsClient)) | ||||||
| { | ||||||
| networkManager.Shutdown(); | ||||||
| networkManager.ShutdownInternal(); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private static void EditorApplication_playModeStateChanged(PlayModeStateChange playModeStateChange) | ||||||
| { | ||||||
| switch (playModeStateChange) | ||||||
|
|
||||||
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.
NGOv2.X offers support from 6000.0 editor so I don't think this
ifis neededThere 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.
The same check is used elsewhere in the same file, but happy to remove it if it's not needed.
Uh oh!
There was an error while loading. Please reload this page.
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.
Yeah, remove it. I guess we just missed some stuff to cleanup. I will follow up on it