Search Unity

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

Resolved Knowing when a Lobby is full

Discussion in 'Lobby' started by MarcoZVincenzi, Sep 29, 2023.

  1. MarcoZVincenzi


    Mar 3, 2022
    We are trying the Unity Lobby system, but we can't seem to answer this seemingly simple questions: How can a Host know when the lobby is full so that they can start a game session?

    We've been reading the docs, but we can't seem to find anything specific. Isn't there something like a lobby event that can notify the client about the lobby reaching capacity?
    Sure, we could have every player write their custom data in the Lobby to signal their presence, or subscribe to the Player Joined event, as a way to get the current number of players in the lobby. Then we could compare
    currentPlayers == maxPlayers
    to know this, but what is the best practice that Unity expects developers to follow?

  2. bartj-unity


    Unity Technologies

    Sep 9, 2021

    There is no specific event for a lobby reaching capacity. Your suggestion about using the existing events would be easiest. Either use the player joined events as you mention, or use the lobby updated events to wait until the AvailableSlots property of the lobby equals 0.
    MarcoZVincenzi likes this.
  3. MarcoZVincenzi


    Mar 3, 2022
    Thanks, I ended up reading the value of AvailableSlots to check if the room is full.

    For anyone wondering, my implementation looks something like this:
    Code (CSharp):
    1. var callbacks = new LobbyEventCallbacks();
    2. callbacks.LobbyChanged += OnLobbyChanged;
    Code (CSharp):
    1. private void OnLobbyChanged(ILobbyChanges _changes)
    2. {
    3.     if (_changes.AvailableSlots.Value == 0)
    4.     {
    5.         OnLobbyFull?.Invoke();
    6.     }
    7. }
    Last edited: Oct 2, 2023