diff --git a/Assets/Mirror/Core/NetworkManager.cs b/Assets/Mirror/Core/NetworkManager.cs
index ba18a31b7..9a886fd98 100644
--- a/Assets/Mirror/Core/NetworkManager.cs
+++ b/Assets/Mirror/Core/NetworkManager.cs
@@ -634,31 +634,6 @@ public void StopClient()
NetworkClient.Disconnect();
}
- // called when quitting the application by closing the window / pressing
- // stop in the editor. virtual so that inheriting classes'
- // OnApplicationQuit() can call base.OnApplicationQuit() too
- public virtual void OnApplicationQuit()
- {
- // stop client first
- // (we want to send the quit packet to the server instead of waiting
- // for a timeout)
- if (NetworkClient.isConnected)
- {
- StopClient();
- //Debug.Log("OnApplicationQuit: stopped client");
- }
-
- // stop server after stopping client (for proper host mode stopping)
- if (NetworkServer.active)
- {
- StopServer();
- //Debug.Log("OnApplicationQuit: stopped server");
- }
-
- // Call ResetStatics to reset statics and singleton
- ResetStatics();
- }
-
/// Set the frame rate for a headless builds. Override to disable or modify.
// useful for dedicated servers.
// useful for headless benchmark clients.
@@ -772,12 +747,41 @@ public static void ResetStatics()
singleton = null;
}
- // virtual so that inheriting classes' OnDestroy() can call base.OnDestroy() too
+ // called when quitting the application by closing the window / pressing
+ // stop in the editor.
+ // use OnDestroy instead of OnApplicationQuit:
+ // fixes: https://github.com/MirrorNetworking/Mirror/issues/2802
public virtual void OnDestroy()
{
//Debug.Log("NetworkManager destroyed");
+
+ // stop client first
+ // (we want to send the quit packet to the server instead of waiting
+ // for a timeout)
+ if (NetworkClient.isConnected)
+ {
+ StopClient();
+ //Debug.Log("OnApplicationQuit: stopped client");
+ }
+
+ // stop server after stopping client (for proper host mode stopping)
+ if (NetworkServer.active)
+ {
+ StopServer();
+ //Debug.Log("OnApplicationQuit: stopped server");
+ }
+
+ // Call ResetStatics to reset statics and singleton
+ ResetStatics();
}
+ // [Obsolete] in case someone is inheriting it.
+ // don't use this anymore.
+ // fixes: https://github.com/MirrorNetworking/Mirror/issues/2802
+ // DEPRECATED 2024-10-29
+ [Obsolete("Override OnDestroy instead of OnApplicationQuit. Fixes: https://github.com/MirrorNetworking/Mirror/issues/2802")]
+ public virtual void OnApplicationQuit() {}
+
/// The name of the current network scene.
// set by NetworkManager when changing the scene.
// new clients will automatically load this scene.
diff --git a/Assets/Mirror/Core/Transport.cs b/Assets/Mirror/Core/Transport.cs
index 9cad04c37..ae9b37a86 100644
--- a/Assets/Mirror/Core/Transport.cs
+++ b/Assets/Mirror/Core/Transport.cs
@@ -197,7 +197,9 @@ public virtual void ServerLateUpdate() {}
public abstract void Shutdown();
/// Called by Unity when quitting. Inheriting Transports should call base for proper Shutdown.
- public virtual void OnApplicationQuit()
+ // use OnDestroy instead of OnApplicationQuit:
+ // fixes: https://github.com/MirrorNetworking/Mirror/issues/2802
+ public virtual void OnDestroy()
{
// stop transport (e.g. to shut down threads)
// (when pressing Stop in the Editor, Unity keeps threads alive
diff --git a/Assets/Mirror/Examples/AutoLANClientController/Scripts/AutoLANNetworkManager.cs b/Assets/Mirror/Examples/AutoLANClientController/Scripts/AutoLANNetworkManager.cs
index 392e282b3..c04437c0c 100644
--- a/Assets/Mirror/Examples/AutoLANClientController/Scripts/AutoLANNetworkManager.cs
+++ b/Assets/Mirror/Examples/AutoLANClientController/Scripts/AutoLANNetworkManager.cs
@@ -62,15 +62,6 @@ public override void LateUpdate()
base.LateUpdate();
}
- ///
- /// Runs on both Server and Client
- ///
- public override void OnDestroy()
- {
- base.OnDestroy();
- //UnityEngine.Debug.Log("OnDestroy");
- }
-
#endregion
#region Start & Stop
@@ -87,10 +78,10 @@ public override void ConfigureHeadlessFrameRate()
///
/// called when quitting the application by closing the window / pressing stop in the editor
///
- public override void OnApplicationQuit()
+ public override void OnDestroy()
{
- base.OnApplicationQuit();
- //UnityEngine.Debug.Log("OnApplicationQuit");
+ base.OnDestroy();
+ //UnityEngine.Debug.Log("OnDestroy");
}
#endregion
diff --git a/Assets/Mirror/Examples/PlayerTest/PlayerTestNetMan.cs b/Assets/Mirror/Examples/PlayerTest/PlayerTestNetMan.cs
index 1f8606985..a770fac90 100644
--- a/Assets/Mirror/Examples/PlayerTest/PlayerTestNetMan.cs
+++ b/Assets/Mirror/Examples/PlayerTest/PlayerTestNetMan.cs
@@ -71,14 +71,6 @@ public override void ConfigureHeadlessFrameRate()
base.ConfigureHeadlessFrameRate();
}
- ///
- /// called when quitting the application by closing the window / pressing stop in the editor
- ///
- public override void OnApplicationQuit()
- {
- base.OnApplicationQuit();
- }
-
#endregion
#region Scene Management