Mirror
Mirror copied to clipboard
Reloading scene not working after updating Mirror to 5.1.8
We updated Mirror to 5.1.8 recently and it broke the level restart in our game (both restarting from menu or game over). This is an issue in singleplayer only. Multiplayer uses a different game mode, where restarting is not allowed, so it is not an issue there regardless of whether it is local or online multiplayer.
Our code now calls StartHost() from NetworkManager.cs when a level starts (regardless of if it is a restart or not). This now causes the game to be stuck and not starting to reload the scene. If we try to stop the server with StopHost() before starting the new one, the game returns to offline scene.
I'm not sure if the implementation is wrong, but I'd like to know how this is supposed to be done, or if something was changed in Mirror that broke the old implementation.
This sounds like bad implementation on your end to be honest. Calling StartHost over and over on level changes is bound to cause issues eventually even if Mirror realizes it's already hosting (a unwanted recursion effect comes to mind).
If you're hosting a game and you call Mirror's Server Change Scene function then all clients will get the memo and switch over to the new level. No need to stop the server or restart it.
Alternatively, to prevent it from switching to an offline scene, temporarily set the offline scene field to blank so Mirror will not load the disconnected/offline scene. Then do your stuff, set online scene to the proper one and go StartHost again.
For more help, refer to the Discord.