Search Unity

Resolved Lobby Quick Join is not working?

Discussion in 'Netcode for GameObjects' started by JJunior, Jul 21, 2022.

  1. JJunior

    JJunior

    Joined:
    May 22, 2019
    Posts:
    53
    Hello,

    I am trying to implement a lobby quick join but its not working.

    I will explain all the steps:

    1. The first client creates a new Lobby:

    Code (CSharp):
    1. await LobbyService.Instance.CreateLobbyAsync( _lobbyName, 10);
    * I am heart beating the lobby every 10 seconds.
    * I also tried create it using the IsPrivate = false option

    2. A second client tries to connect a lobby with the same _lobbyName

    Code (CSharp):
    1. QuickJoinLobbyOptions options = new QuickJoinLobbyOptions();
    2.  
    3.             options.Filter = new List<QueryFilter>()
    4.             {
    5.                 new QueryFilter(
    6.                     field: QueryFilter.FieldOptions.Name,
    7.                     op: QueryFilter.OpOptions.EQ,
    8.                     value: _lobbyName)
    9.             };
    10.  
    11.             _currentLobby = await LobbyService.Instance.QuickJoinLobbyAsync(options);
    Its throwing a LobbyServiceException, basictly its not finding it.

    I also tried a QuickJoinLobbyAsync with no options and had no success.

    I did a LobbyService.Instance.QueryLobbiesAsync without any options filters in the second client just to be sure if the lobby was created by host, and it was, the lobby was in the result list. I think the QuickJoinLobby is not working or I am doing something wrong.

    Any ideas?
     
    Last edited: Jul 21, 2022
  2. JJunior

    JJunior

    Joined:
    May 22, 2019
    Posts:
    53
    I just changed my code to use QueryLobbiesAsync to get the lobby I want and it worked. I used the same filters used in JoinLobbyByIdAsync...

    I am pretty sure it's a bug in JoinLobbyByIdAsync. I am using ParrelSync to test, I am not sure if it's related.

    Another thing that I just realized is that when I do a SignInAnonymouslyAsync I get the same PlayerId on both unity instances, this was causing some issues in my code, once I was checking the HostId of the lobby to delete the lobby or just leave the lobby.

    Is this the expected behavior of the Auth system? A SignInAnonymouslyAsync should not alway return a new user?
     
  3. JJunior

    JJunior

    Joined:
    May 22, 2019
    Posts:
    53
    I just found a solution, the quick join was not working because I was trying to connect using the same user profile.

    I just changed the InitializeUnityServicesAsync method. As I am using ParrelSync, I just use the argument to set the player profile.

    https://docs.unity.com/authentication/ProfileManagement.html

    Code (CSharp):
    1. public async Task InitializeUnityServicesAsync()
    2.     {
    3.         var options = new InitializationOptions();
    4.         if (ClonesManager.IsClone())
    5.         {
    6.             options.SetProfile(ClonesManager.GetArgument());
    7.         }
    8.         await UnityServices.InitializeAsync(options);
    9.     }
    Now the quick join is working just fine.
     
  4. ItsNoxL

    ItsNoxL

    Joined:
    Dec 13, 2020
    Posts:
    4
    I was also struggling with this and didn't know what to do. This totally fixed it! Thank you.
     
  5. ViktorMSc

    ViktorMSc

    Joined:
    May 28, 2022
    Posts:
    14
    Just a little tip. You do not need to do any checks, just set the profile to a random string.

    Code (CSharp):
    1.     private async Task Authenticate() {
    2.         var options = new InitializationOptions();
    3.         var profile = Guid.NewGuid().ToString().Substring(0, 8);
    4.         options.SetProfile(profile);
    5.  
    6.         await UnityServices.InitializeAsync(options);
    7.  
    8.         await AuthenticationService.Instance.SignInAnonymouslyAsync();
    9.     }
     
    Rungling likes this.