Proper way to disconnect from UNET lobby?

EDIT: I had a breakthrough! I mostly found the answer, although it creates some follow-up questions. See below!

With HLAPI (LobbyNetworkManager / NetworkLobbyPlayer classes), How do I properly leave a lobby room as a host? As a client?

The documentation is incredibly minimal, if not non-existing altogether O__o I am stumped. I’m trying a few things which I’ll start documenting below.

What I tried:

  • Do nothing and just try to matchMake again (list > join 1st game OR create game if none):
    I join my old game that no longer has a host. After ~30 seconds, the lobby destroys itself and I get errors. This surely isn’t right, but that’s where I started.

  • Now - When I click my cancelBtn, it calls:

  • matchMaker.DropConnection(matchInfo.networkId, matchInfo.nodeId, 0, OnMatchDropConnection);*
    I don’t rejoin my own match anymore, but I get the same errors This Post has some info.

  • I am now looking into DestroyMatch(), but the docs say that DropConnection is the best way to go. Also, what if I’m not the client? I won’t have permission to destroy the match, anyway. So, what do I do?

  • 12/11: Apparently most destroy/drop tactics destroy your NetworkLobbyManager instance, but I still get errs when attempting to requeue where it seemingly works.

  • Tried to StopMatchMaker() as another thread (lost link) suggested may work, but I get the same errs as the 2nd bullet above (already have a connection and can only have 1 / controller exists already)

GOT IT!! Not sure if this is standard (if a Unity dev pops in, let me know):

User clicks the “stop queue” arbitrary button to trigger the NetworkLobbyManager class script to:

if (this.matchInfo != null)
            this.StopHost();
  • When a client does this, the client immediately leaves the lobby. Don’t be fooled by the word host - this will do client events if client. This is what through me off the most: I’m thinking “hm i’m a client not a host…”.
  • The “real host” remains in the lobby and others can join.
  • If you list and join/create matches thereafter, it will work with no error!
  • Still testing what happens if the match host uses StopHost()

Remaining questions:

  • Will StopHost, if used by a host, kick off all the clients?
  • ^ If so, how would I migrate the host? Shame if 14 people queued up and the host leaves, kicking everyone out… right?
1 Like

When I host a match, make a second client join and alt+f4 the host instance, my second client is kicked out of the lobby. I think this will happen also for your case. But I know there is something called HostMigration. But I just didnt look into it because I am still in early development stage. Thanks for your evaluations!