diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs index 66f1a67e3b..898a8973bf 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs @@ -1323,7 +1323,17 @@ public bool StartServer() } ConnectionManager.LocalClient.ClientId = ServerClientId; - Initialize(true); + try + { + Initialize(true); + } + catch (Exception ex) + { + Debug.LogException(ex); + // Always shutdown to assure everything is cleaned up + ShutdownInternal(); + return false; + } try { @@ -1342,11 +1352,13 @@ public bool StartServer() ConnectionManager.TransportFailureEventHandler(true); } - catch (Exception) + catch (Exception ex) { + Debug.LogException(ex); + // Always shutdown to assure everything is cleaned up + ShutdownInternal(); ConnectionManager.LocalClient.SetRole(false, false); IsListening = false; - throw; } return IsListening; @@ -1373,7 +1385,16 @@ public bool StartClient() return false; } - Initialize(false); + try + { + Initialize(false); + } + catch (Exception ex) + { + Debug.LogException(ex); + ShutdownInternal(); + return false; + } try { @@ -1419,7 +1440,18 @@ public bool StartHost() return false; } - Initialize(true); + try + { + Initialize(true); + } + catch (Exception ex) + { + Debug.LogException(ex); + // Always shutdown to assure everything is cleaned up + ShutdownInternal(); + return false; + } + try { IsListening = NetworkConfig.NetworkTransport.StartServer(); @@ -1437,6 +1469,8 @@ public bool StartHost() catch (Exception ex) { Debug.LogException(ex); + // Always shutdown to assure everything is cleaned up + ShutdownInternal(); ConnectionManager.LocalClient.SetRole(false, false); IsListening = false; }