Cannot start Host while an instance is already running

Hi everybody,

My game occasionally loses connection, the lobby works normally but when 2 players are ready, they cannot connect to each other. Here is the error:

2024/04/30 14:16:28.452 19535 19595 Warn Unity [Netcode] Cannot start Host while an instance is already running
2024/04/30 14:16:28.452 19535 19595 Warn Unity Unity.Netcode.NetworkManager:CanStart(StartType)
2024/04/30 14:16:28.452 19535 19595 Warn Unity Unity.Netcode.NetworkManager:StartHost()
2024/04/30 14:16:28.452 19535 19595 Warn Unity d__55:MoveNext()
2024/04/30 14:16:28.452 19535 19595 Warn Unity System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
2024/04/30 14:16:28.452 19535 19595 Warn Unity System.Runtime.CompilerServices.MoveNextRunner:Run()
2024/04/30 14:16:28.452 19535 19595 Warn Unity System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
2024/04/30 14:16:28.452 19535 19595 Warn Unity System.Threading.Tasks.Task:FinishContinuations()
2024/04/30 14:16:28.452 19535 19595 Warn Unity System.Threading.Tasks.Task1:TrySetResult(TResult) 2024/04/30 14:16:28.452 19535 19595 Warn Unity System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetResult(TResult)
2024/04/30 14:16:28.452 19535 19595 Warn Unity d__57:MoveNext()
2024/04/30 14:16:28.452 19535 19595 Warn Unity System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
2024/04/30 14:16:28.452 19535 19595 Warn Unity System.Runtime.CompilerServices.MoveNextRunner:Run()
2024/04/30 14:16:28.452 19535 19595 Warn Unity System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
2024/04/30 14:16:28.452 19535 19595 Warn Unity System.Threading.Tasks.Task:FinishContinuations()
2024/04/30 14:16:28.452 19535 19595 Warn Unity System.Threading.Tasks.Task1:TrySetResult(TResult) 2024/04/30 14:16:28.452 19535 19595 Warn Unity System.Runtime.CompilerServices.As 2024/04/30 14:16:28.653 19535 19595 Warn Unity [Netcode] Cannot start Host while an instance is already running 2024/04/30 14:16:28.653 19535 19595 Warn Unity Unity.Netcode.NetworkManager:CanStart(StartType) 2024/04/30 14:16:28.653 19535 19595 Warn Unity Unity.Netcode.NetworkManager:StartHost() 2024/04/30 14:16:28.653 19535 19595 Warn Unity <CreateNetworkManager>d__55:MoveNext() 2024/04/30 14:16:28.653 19535 19595 Warn Unity System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean) 2024/04/30 14:16:28.653 19535 19595 Warn Unity System.Runtime.CompilerServices.MoveNextRunner:Run() 2024/04/30 14:16:28.653 19535 19595 Warn Unity System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&) 2024/04/30 14:16:28.653 19535 19595 Warn Unity System.Threading.Tasks.Task:FinishContinuations() 2024/04/30 14:16:28.653 19535 19595 Warn Unity System.Threading.Tasks.Task1:TrySetResult(TResult)
2024/04/30 14:16:28.653 19535 19595 Warn Unity System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetResult(TResult) 2024/04/30 14:16:28.653 19535 19595 Warn Unity <SetRelayHostData>d__57:MoveNext() 2024/04/30 14:16:28.653 19535 19595 Warn Unity System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean) 2024/04/30 14:16:28.653 19535 19595 Warn Unity System.Runtime.CompilerServices.MoveNextRunner:Run() 2024/04/30 14:16:28.653 19535 19595 Warn Unity System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&) 2024/04/30 14:16:28.653 19535 19595 Warn Unity System.Threading.Tasks.Task:FinishContinuations() 2024/04/30 14:16:28.653 19535 19595 Warn Unity System.Threading.Tasks.Task1:TrySetResult(TResult)
2024/04/30 14:16:28.653 19535 19595 Warn Unity System.Runtime.CompilerServices.As

Sounds like the host is already running a game as either host or client. Check your netcode shutdown logic. Note that you may have to let some time pass between disconnect and Start… calls.

For further analysis post your code.

1 Like

Thank you for your quick reply, I have used NetworkManager.Singleton.Shutdown(true); to disconnect when the user exits the game, in addition to lobby handling logic. I can’t determine where this error comes from?

Does the error occur only when the user had hosted a game before?

If so the Shutdown isn’t complete, or not happening. Check if perhaps you have duplicate NetworkManager instances in your scene. This is a common issue when you have NetworkManager in a scene that you’re loading again. Therefore NetworkManager ought to be in some sort of “launch” scene that is never loaded again.

1 Like

Thank you, I have fixed this error. This is because NetworkManager is not destroyed and duplicated many times

1 Like

For those who encounter this error, if you start the host many times in a short period of time it will also cause this error.