Documentation

Support

Lobby

Lobby

Leave a lobby

Learn how players can leave a lobby and what happens when they exit.
Read time 1 minuteLast updated 15 hours ago

When players leave a lobby or get kicked out of the lobby, their player ID is removed from the players list. If the host leaves the lobby, another player in the lobby is randomly selected as the host. The host can also remove other players from the lobby. The same
RemovePlayerAsync
API call is used in both cases where the host simply specifies the other player's
playerId
instead of their own. Lobbies are automatically deleted when the last player in the lobby leaves.
The following code sample shows how to remove a player from the lobby: C#
try{ //Ensure you sign-in before calling Authentication Instance //See IAuthenticationService interface string playerId = AuthenticationService.Instance.PlayerId; await LobbyService.Instance.RemovePlayerAsync(lobbyId, playerId);}catch (LobbyServiceException e){ Debug.Log(e);}
where
  • lobbyId
    is the ID of the lobby the player is trying to leave
  • playerID
    is the ID of the player leaving the lobby

Leave a lobby • Lobby • Unity Docs