Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question Query for created lobbies does not find any lobbys

Discussion in 'Lobby' started by bCatLive, Nov 25, 2022.

  1. bCatLive

    bCatLive

    Joined:
    Oct 24, 2022
    Posts:
    2
    Hello,

    I´m new to Unity Multiplayer section and trying to create a simple multiplayer game while using Unity Lobby. I´ve managed to create a lobby and join it with another instance of my application using the provided join code. Now when I try to query for existing lobbys to show them to the user as options no matter what I try to do the query yields 0 results. Is there anything I might be missing ?

    Here is how I create my lobby:
    Code (CSharp):
    1.     public static async Task CreateLobby(LobbyConfig config)
    2.     {
    3.         transport = Object.FindObjectOfType<UnityTransport>();
    4.         var alloc = await RelayService.Instance.CreateAllocationAsync(config.maxPlayerAmount);
    5.         var joinCode = await RelayService.Instance.GetJoinCodeAsync(alloc.AllocationId);
    6.  
    7.         var lobbyOptions = new CreateLobbyOptions
    8.         {
    9.             Data = new Dictionary<string, DataObject>
    10.             {
    11.                 { Constants.JoinCode, new DataObject(DataObject.VisibilityOptions.Member,joinCode)},
    12.                 { Constants.LobbyName, new DataObject(DataObject.VisibilityOptions.Public,config.lobbyName)}
    13.             }
    14.         };
    15.  
    16.         lobbyOptions.IsPrivate = false;
    17.         currentLobby = await Lobbies.Instance.CreateLobbyAsync(config.lobbyName,config.maxPlayerAmount,lobbyOptions);
    18.  
    19.         transport.SetHostRelayData(alloc.RelayServer.IpV4, (ushort)alloc.RelayServer.Port,alloc.AllocationIdBytes,alloc.Key,alloc.ConnectionData);
    20.         Debug.Log("Lobbyname: " + currentLobby.Name);
    21.         Debug.Log("LobbyCode: " + currentLobby.LobbyCode);
    22.         Debug.Log("Private: "+ currentLobby.IsPrivate);
    23.         Debug.Log("Slots: " + (currentLobby.MaxPlayers - currentLobby.AvailableSlots)+"/" + currentLobby.MaxPlayers);
    24.         PingCurrentLobby(); //Heartbeat
    25.         RefreshLobby();
    26.     }
    and here how I try to find it:
    Code (CSharp):
    1.     public static async Task<List<Lobby>> SearchLobbies()
    2.     {
    3.         var foundLobbies = await Lobbies.Instance.QueryLobbiesAsync();
    4.         Debug.Log("LobbyCount: " + foundLobbies.Results.Count);
    5.  
    6.         return foundLobbies.Results;
    7.     }
    Thanks in advance!
     
  2. RobustKnittedTortoise

    RobustKnittedTortoise

    Unity Technologies

    Joined:
    Dec 10, 2018
    Posts:
    16
    Just want to clarify your heartbeat code and how that affects queries.
    I see you have a method
    PingCurrentLobby(); //Heartbeat

    Does that continually heartbeat the lobby or just do it once?

    The lobby must receive a heartbeat at least every 30 seconds or it will not show up in queries/quick joins.
    The query code to find it should be fine, off the top of my head, the only reasons the search code could fail are:
    • the lobby became stale (no host heartbeat in 30 seconds)
    • The other client/editor is not configured to look at the exact same project Ids?
    • Something running after
      CreateLobby(LobbyConfig config)
      executs is deleting the lobby.
     
    Last edited: Nov 27, 2022
  3. bCatLive

    bCatLive

    Joined:
    Oct 24, 2022
    Posts:
    2
    Thanks for the answer, I revisited my heartbeat-function and yes there was an error which caused it to not repeat the heartbeat. Now I can find my lobbys.

    Thanks for the help