Unity changing server when it disconnects

I'm making a coop game in Unity. It's designed to be drop-in/drop-out. Currently there's one player who's the server. Though I was wondering, is it possible to change the player who's considered the server in case the current server disconnects.

I wasn't sure what to call this, so my Googling turned up nothing.

Thanks!

Answers


This is known as "Host Migration", and it is a little advanced. What you need to do is initialize a new server when the old one quits, the problem comes when you need to make a connection from other players, and make the objects stay.

What I would do is make a list that is the exact same for every player, which means that when one disconnects they should join the next server in queue, but only after waiting for a set amount of time, 5-10 seconds should be long enough, probably shorter works. Then you will need to re-make network instantiated objects due to when a host disconnects the client obviously looses connection, causing all network instantiated objects to be destroyed, so they will need to be re-made. Typically not many objects need to be remade, probably AI, and players, AI being somewhat optional. My advice would be to store the players information, health, position, rotation, etc. In your level/networking manager (if you have one).

If you would like an easier way, there is always photon cloud networking, which does this for you, just it comes at a price.


Need Your Help

Ensure npm install -g does not need sudo?

macos npm sudo

On MacOS X an npm install -g requires a user to sudo, though we would like to have it so the 'global' mode is per user, rather than system wide. Does anyone know if this is possible? We would like to

DBAnnotations - Duplicate Annotaion

java mysql sql database annotations

As a part of my course project we have been asked to annotate our code.