Unity-Technologies/com.unity.multiplayer.samples.coop

Host Migration implementation so the game doesn't end when the host leaves

styliann-eth opened this issue · 3 comments

Is your feature request related to a problem? Please describe.
Currently in Boss Room I believe all client listen to the OnClientDisconnect callback and then shutdown/return to main menu when the host leaves.

Describe the solution you'd like
This post from Luke last year gave a basic outline of what this could look like:

There are some ways you could add host migration to a game using the Photon Realtime Transport. Something along the line of the following should work:

  1. While still all clients are connected use a NetworkVariable to agree on a fallback client which will be next in case of the host disconnects.
  2. If the host disconnects have that that fallback client create a new room with a slightly different name like "_1" by starting MLAPI again as host with a different room name and have all other clients connect again to that new room.

To get that to work the fallback client will need some way to store the current game state when stopping MLAPI and spawning the right objects again when entering host mode after the migration.

Would it be possible to implement? All production p2p games need this.

The post you are referring to is this one right?

@ns2808 did you have any issues trying this on your side? Did you have any specific items you'd like to see in a sample? I can't guarantee we'd do this in boss room, but there's a possibility of a bitesize for this. However, we'd need to know what kinds of issues you encountered on your side to triage.
A way I'd see this work with NGO 1.0 is to keep a state manager on the side that keeps track of your important game data and have that data tracked by the elected fallback client.
So:

  • have all clients know the fallback client's address/relay join code (could be tracked in UGS' lobby's data for example)
  • track your game state in a manager on that fallback client
  • when host fails, fallback client unloads everything, shutdown its network manager and StartHost, reloads everything using that game state manager
  • all other clients unload everything and "late join" the fallback client.

Correction on the above @ns2808 :
From this thread here, host migration isn't supported. Jesse mentions a few things that'd need to be looked at. There's a lot of edge cases you'd need to implement yourself.

  • Your game shouldn't use NetworkShow/Hide
  • It should have custom scene syncing (like described in our doc)
  • use a lobby service for communicating new host info
  • shutdown and StartHost with the UTP transport (no need for a state manager like I mentioned above, you could use the netvars values already stored client side to start a new host)
  • have a session manager (like we have in boss room) and sync it with the next host
  • accept that some host migrations will take time or fail (which is already the case for call of duty according to this page here for example)