I attached a simple project with 13 lines of code that shows how NetworkManager:OnServerDisconnect is never called when the host disconnects. This is a problem because often game servers need to save player data after the player quits the game. This works fine for clients that connect to the server, because OnServerDisconnect is called when those clients quit the game.
It is however not called when I run the server as host (aka I also play on it) and then stop the server (either with the Unity Editor stop button, or with the GUI stop button in the NetworkManagerHud). I think it should be called because we need some kind of “onquit” function to save the host data too. OnServerDisconnect would be perfect for this because it happens before “OnDestroy”, hence we can be 100% sure that the player objects hasn’t been destroyed yet and can still be saved.
How to reproduce:
- Open the Project, open the Scene
- Press Play
- Select “Start Host”
- Stop it
- See how there is no log message because NetworkManagerCustom:OnServerDisconnect is not called
[Tested on Unity 5.3.1f1]
2465117–169640–networkmanager onserverdisconnect not called when quitting the editor.zip (37.8 KB)