1

I've got a ResetNetworkManager method that's called when the server or client needs to clean up its state. One of these situations is when the server is shut down. This either happens when the Stop Server button is clicked, and when the method returns the start scene is loaded. In this situation the MatchInfo of the server's match is also passed in, and the NetworkMatch.DestroyMatch is called.

In the situation where the Stop Server button is clicked, everything works fine. The match is immediately removed from the match making service, and clients don't see it when they list matches.

However, when the server's app is shut down, the same method is called from another GameObject's OnDestroy method. However, in this situation the call doesn't seem to work, possibly because the NetworkMatch.DestroyMatch method actually starts a Coroutine, and this coroutine doesn't get far enough in its execution before it's killed with it's GameObject.

This is a problem as the server would normally run in batchmode, so the only way they get shut down is by killing them, rather than by clicking the button (only used when testing the server in ui mode.

Does anyone know how to make sure the match is destroyed when the app is suddenly shut down? I know you can't make OnDestroy a Coroutine, which would otherwise have been a nice solution...

Here is the code of the ResetNetworkManager method:

public void ResetNetworkManager(MatchInfo matchToDestroy)
{
    if (matchToDestroy != null)
    {
        matchMaker.DestroyMatch(matchToDestroy.networkId, 0, MatchDestroyed);
    }
    StopServer();
    StopClient();
    StopHost();
    StopMatchMaker();
    if (_gameStateManager != null)
    {
        NetworkServer.Destroy(_gameStateManager.gameObject);
        _gameStateManager = null;
    }
    Destroy(gameObject);
    NetworkServer.Reset();
}
Svend Hansen
  • 3,277
  • 3
  • 31
  • 50

0 Answers0