Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to keep lobby code active after the lobby is empty?

Discussion in 'Lobby' started by Amandou, Oct 10, 2023.

  1. Amandou

    Amandou

    Joined:
    Apr 4, 2020
    Posts:
    3
    Hello,

    I'm making a game using lobby and relay that the player can create and enter in rooms. The player can enter the room automatically, so there is no need to wait others players to join or wait the host to allow joining a room.

    Each room is a lobby, and the players are connected using relay. I notice when everyone leaves a lobby after some seconds this lobby is deleted with its lobby code. This behavior occurs when the game is closed too.

    I would like to keep the lobby code alive to rejoin a lobby or create another lobby with this former lobby code. How can I do this?
     
    Last edited: Oct 13, 2023
  2. bartj-unity

    bartj-unity

    Unity Technologies

    Joined:
    Sep 9, 2021
    Posts:
    26
    I don't think there's an exact match for what you're asking for, but there are 2 related options you might consider:
    • If you create/manage a lobby using a service account, when the last player leaves and the lobby becomes empty, it will not be deleted like it would be in a player-managed lobby. You could use this in tandem with some mechanism for heartbeating the lobby to keep it active (and thus prevent deletion by the Lobby service itself) in between games.
    • If it would be acceptable to maintain a consistent lobby ID instead of code, you could use the Create Or Join API to keep the same lobby reference from game to game.
     
  3. Amandou

    Amandou

    Joined:
    Apr 4, 2020
    Posts:
    3
    Thanks for the answer!

    I guess I can replace the lobby code for the lobby ID, I did a simple test: I joined 2 lobbies, after that quit my game and play it again and l verified my joined lobbies using LobbyService.Instance.GetJoinedLobbiesAsync();

    My question is for how long seconds or minutes the lobby ID will be saved?