Search Unity

Question Do I need to keep the Lobby heartbeat going throughout the game?

Discussion in 'Lobby' started by WakingDragon, Nov 11, 2022.

  1. WakingDragon

    WakingDragon

    Joined:
    Mar 18, 2018
    Posts:
    41
    Once it has done its work of connecting up two players, is there any reason to keep the heartbeat going or can I just let the lobby go gently into the night?

    thanks
    B
     
  2. RobustKnittedTortoise

    RobustKnittedTortoise

    Unity Technologies

    Joined:
    Dec 10, 2018
    Posts:
    16
    There are two main uses of the lobby heartbeat:
    1. Queries/QuickJoins by default, ignore any lobby that hasn't received a heartbeat in the last 30 seconds. The main purpose of this is to avoid players from continually finding/joining lobbies that have an inactive host (we don't want a single inactive host to cause players to join, wait, realize the host is inactive, then quit and possibly rejoin the same lobby again later!).
    2. Keep the lobby from being auto cleaned up; lobbies are eventually removed when there is no activity from the host.
    If you are saying you don't need the lobby or any of its features anymore, as it has already done the job of connecting your players, then just have the host delete the lobby directly. This is preferable to letting it slowly fade away, as there is an API that shows what lobbies a player is part of and it would be good to keep those in sync. Also, as arguments for NOT deleting it (if any of these apply), there are some features that lobby can provide beyond just initial connection of two players:
    • a way to represent state in case your client crashes and wants to rediscover some data (reconnect)
    • when integrated with relay, there is messaging that can disconnect a host/player when the relay itself detects the player has disconnected.
    • a way to easily get/join a voice channel