Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question [Lobby]: ValidationError, (16000). Message: request failed validation

Discussion in 'Lobby' started by orcunsari, May 18, 2023.

  1. orcunsari

    orcunsari

    Joined:
    Jul 21, 2016
    Posts:
    22
    Hi, I get this error when I tried to create lobby.

    Problem occurs like this.

    -I simply initialize services then in SignIn callback I create lobby. It creates lobby without problem.
    -Then I exit playmode. It disposes lobby and removes all players bind to that lobby.
    -On second time I enter play mode and repeat first step, I get error at LobbyService.Instance.CreateLobbyAsync();

    Here's my Authentication Code.

    Code (CSharp):
    1.         private static async Task<bool> TryInitServicesAsync(string profileName = null)
    2.         {
    3.             if (UnityServices.State == ServicesInitializationState.Initialized)
    4.                 return true;
    5.  
    6.             //Another Service is mid-initialization:
    7.             if (UnityServices.State == ServicesInitializationState.Initializing)
    8.             {
    9.                 var task = WaitForInitialized();
    10.                 if (await Task.WhenAny(task, Task.Delay(InitTimeout)) != task)
    11.                     return false; // We timed out
    12.  
    13.                 return UnityServices.State == ServicesInitializationState.Initialized;
    14.             }
    15.  
    16.             if (profileName != null)
    17.             {
    18.                 //ProfileNames can't contain non-alphanumeric characters
    19.                 Regex rgx = new Regex("[^a-zA-Z0-9 - _]");
    20.                 profileName = rgx.Replace(profileName, "");
    21.                 var authProfile = new InitializationOptions().SetProfile($"{profileName}{LocalProfileTools.LocalProfileSuffix}");
    22.  
    23.                 //If you are using multiple unity services, make sure to initialize it only once before using your services.
    24.                 await UnityServices.InitializeAsync(authProfile);
    25.             }
    26.             else
    27.                 await UnityServices.InitializeAsync();
    28.  
    29.             return UnityServices.State == ServicesInitializationState.Initialized;
    30.  
    31.             async Task WaitForInitialized()
    32.             {
    33.                 while (UnityServices.State != ServicesInitializationState.Initialized)
    34.                     await Task.Delay(100);
    35.             }
    36.         }
    37.  
    38.         public static async Task<bool> TrySignInAndCreateLobbyAsync(string profileName = null)
    39.         {
    40.             if (!await TryInitServicesAsync(profileName))
    41.                 return false;
    42.          
    43.             Debug.Log("Unity service initialized");
    44.          
    45.             AuthenticationService.Instance.SignedIn += async () =>
    46.             {
    47.                 Debug.Log($"Signed in as {AuthenticationService.Instance.PlayerId}");
    48.              
    49.                 LobbyManager.Instance.InitializeLocalUser(AuthenticationService.Instance.PlayerId, profileName);
    50.  
    51.                 // Create the lobby
    52.                 LobbyManager.Instance.CreateLobby($"{LobbyManager.Instance.LocalPlayer.DisplayName.Value}'s room.");
    53.             };
    54.             AuthenticationService.Instance.SignInFailed += (RequestFailedException e) =>
    55.             {
    56.                 GlobalMenuManager.Instance.FocusMenu(MenuEnum.AuthenticateMenu);
    57.                 StringBuilder stringBuilder = new StringBuilder();
    58.  
    59.                 stringBuilder.Append("Reason: ");
    60.                 stringBuilder.AppendLine(e.Source);
    61.                 stringBuilder.Append("Message: ");
    62.                 stringBuilder.AppendLine(e.Message);
    63.                          
    64.                 OutputHandler.Instance.ShowOneWayOutput($"Error {e.ErrorCode}", stringBuilder.ToString(), () =>
    65.                 {
    66.                     Debug.Log("Sign-in failed: " + e.Message);
    67.                     TrySignInAndCreateLobbyAsync();
    68.                 });
    69.             };
    70.          
    71.             if (_isSigningIn)
    72.             {
    73.                 var task = WaitForSignedIn();
    74.                 if (await Task.WhenAny(task, Task.Delay(InitTimeout)) != task)
    75.                     return false; // We timed out
    76.                 return AuthenticationService.Instance.IsSignedIn;
    77.             }
    78.  
    79.             _isSigningIn = true;
    80.             await AuthenticationService.Instance.SignInAnonymouslyAsync();
    81.             _isSigningIn = false;
    82.  
    83.             return AuthenticationService.Instance.IsSignedIn;
    84.  
    85.             async Task WaitForSignedIn()
    86.             {
    87.                 while (!AuthenticationService.Instance.IsSignedIn)
    88.                     await Task.Delay(100);
    89.             }
    90.         }
    And Here's my LobbyManager
    Code (CSharp):
    1.         public void InitializeLocalUser(string playerId, string username)
    2.         {
    3.             _localPlayer.ID.Value = playerId;
    4.             _localPlayer.DisplayName.Value = username;
    5.         }
    6.         public async Task<Lobby> CreateLobbyAsync(string lobbyName, int maxPlayers, bool isPrivate, LocalPlayer localUser)
    7.         {
    8.             if (_createCooldown.IsCoolingDown)
    9.             {
    10.                 Debug.LogWarning("Create lobby hit the rate limit.");
    11.                 return null;
    12.             }
    13.              
    14.             await _createCooldown.QueueUntilCooldown();
    15.              
    16.             CreateLobbyOptions createLobbyOptions = new CreateLobbyOptions()
    17.             {
    18.                 IsPrivate = isPrivate,
    19.                 Player = CreatePlayer(localUser),
    20.                 Data = new Dictionary<string, DataObject>()
    21.                 {
    22.                     { QueueTypeKey, new DataObject(DataObject.VisibilityOptions.Member, ((int)QueueType.Solo).ToString() ) }
    23.                 }
    24.             };
    25.          
    26.             _joinedLobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, createLobbyOptions);
    27.  
    28.             StartHeartBeat();
    29.  
    30.             return _joinedLobby;
    31.         }
    I followed sample code comes with Lobby package so there is similarities.
     
    Last edited: May 18, 2023
  2. Mj-Kkaya

    Mj-Kkaya

    Joined:
    Oct 10, 2017
    Posts:
    156
    Hi, What is the Lobby and Unity version?
     
  3. orcunsari

    orcunsari

    Joined:
    Jul 21, 2016
    Posts:
    22
    Unity 2021.3.24f1
    Lobby 1.1.0-pre.4
    Authentication 2.5.0
    Services Core 1.9.0