Making an attempt at the nightmare that is multiplayer and I got hosting a server down, but when I leave the server, the host button no longer works saying that “Server or Client already started.” I’ve tried so many different things but It either leads to:
“Server or Client already started”
or
“Duplicate NetworkManager, deleting duplicate”
ah, I guess I should have specified: my NetworkManager is just named manager, so replace “manager” there with the name of yours (“NetworkManager.singleton”)
yeah that got rid of the red lines but now I’m back to the other error I mentioned “Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will be destroyed” which replaces the current NetworkManager with a new one, which as a result completely skrews up the Host Lobby button by deleting it’s “on click()”
It’s better to avoid having to destroy the network manager. Instead put it in a start scene which is loaded once before the menu scene so there’s no need to load that scene again.
To find out when the network has shut down take a look at OnServerStopped/OnClientStopped, these are called very near the end of the shutdown process.
That’s just plain bad code!
You’re relying on StopHost to fail with an exception when you run it on a client. All the while this code ignores all other reasons for exceptions to be raised, leading to follow-up issues because the exceptions are simply ignored.
There has got to be some way of doing this:
if (manager.isServer)
manager.StopHost();
else
manager.StopClient();
“‘NetworkManager’ does not contain a definition for ‘isServer’ and no accessible extension method ‘isServer’ accepting a first argument of type ‘NetworkManager’ could be found (are you missing a using directive or an assembly reference?)”
Just a quick note: at the top you’re stopping the client and then doing it properly again at the bottom. Just delete line 96: NetworkManager.singleton.StopClient(); (the one right below the declaration of ReturnMainMenu())