Right now, I’m trying to make a lobby that shows four open slots for players. I wanna make it so when a player joins the lobby, one of the slots becomes their name on the other players’ screens.
I also wanna implement kicking players. I know how to remove a player from a lobby, but I’m not quite sure how to have that execute anything on the kicked player’s side, or have the player list update for anyone else in the lobby.
I don’t know if there’s a callback for that I don’t know about, but any help would be greatly appreciated, thank you!
Using lobby events for should be what you need!
https://docs.unity.com/lobby/en/manual/lobby-events
Specifically the ILobbyChanges PlayerLeft/PlayerJoined changes and the KickedFromLobby callback
What if the game just crash?
Then it do be crashin
I had the same question as you and stumbled upon this post many times while searching for this scenario. After simulating some crashes myself, I figured out exactly what happens and how to deal with this problem.
If a crash occurs on the host side, the game ends as expected and, curiously, instead of eventually going down due to the absence of heartbeats, the lobby is instantly taken down. This means that the lobby inactivity algorithm probably only applies when the lobby has a host.
If a crash occurs on the client side, however, no lobby data will be updated, causing no lobby events to fire, which results in lobby members having access to outdated lobby data regarding players, as you might have guessed in your comment.
One solution I found to this issue was to listen to the NetworkManager.OnClientDisconnectCallback event from the Netcode package to know when to update the lobby data. This way, you won’t have to rely on clients calling LobbyService.Instance.RemovePlayerAsync before leaving the lobby to trigger the ILobbyChanges event. To know what lobby player id to remove when a netcode player id disconnects, you’ll have to keep a dictionary linking these ids that should update during the OnClientConnectedCallback and OnClientDisconnectCallback events.