Hi, I’ve just started looking into the new lobby system. When trying to create a lobby, following the example in the documentation, I receive the error (catch exception) “Unity.Services.Lobbies.LobbyServiceException: HTTP/1.1 401 Unauthorized”
Not sure If I’ve forgotten to enable something or have done something dumb, just struggling to sink my teeth into how the new lobby system works.
Appreciate it if someone could point me in the right direction.
using System;
using System.Collections.Generic;
using Unity.Services.Authentication;
using Unity.Services.Core;
using Unity.Services.Core.Environments;
using Unity.Services.Lobbies;
using Unity.Services.Lobbies.Models;
using UnityEngine;
public class LobbyManager : MonoBehaviour
{
public string environment = "production";
async void Start()
{
await UnityServices.InitializeAsync();
try
{
string lobbyName = "Custom Game Lobby";
int maxPlayers = 16;
// Lobby options
CreateLobbyOptions options = new CreateLobbyOptions();
options.IsPrivate = false;
// lobby data
options.Data = new Dictionary<string, DataObject>();
options.Data.Add("Gamemode", new DataObject(DataObject.VisibilityOptions.Public, "Race", DataObject.IndexOptions.S1));
//lobby player
string playerId = AuthenticationService.Instance.PlayerId;
Dictionary<string, PlayerDataObject> playerData = new Dictionary<string, PlayerDataObject>();
playerData.Add("Name", new PlayerDataObject(PlayerDataObject.VisibilityOptions.Public, "Steve"));
Player player = new Player(playerId, null, playerData);
options.Player = player;
Lobby lobby = await Lobbies.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);
}
catch (Exception ex)
{
Debug.LogError(ex);
}
}
}
Error:
Unity.Services.Lobbies.LobbyServiceException: HTTP/1.1 401 Unauthorized —> Unity.Services.Lobbies.Http.HttpException: HTTP/1.1 401 Unauthorized
at Unity.Services.Lobbies.Http.ResponseHandler.HandleAsyncResponse (Unity.Services.Lobbies.Http.HttpClientResponse response, System.Collections.Generic.Dictionary2[TKey,TValue] statusCodeToTypeMap) [0x00066] in C:\Unity Projects\Table Top Racers\Library\PackageCache\com.unity.services.lobby@1.0.0-pre.6\Runtime\Http\ResponseHandler.cs:101 at Unity.Services.Lobbies.Http.ResponseHandler.HandleAsyncResponse[T] (Unity.Services.Lobbies.Http.HttpClientResponse response, System.Collections.Generic.Dictionary
2[TKey,TValue] statusCodeToTypeMap) [0x00000] in C:\Unity Projects\Table Top Racers\Library\PackageCache\com.unity.services.lobby@1.0.0-pre.6\Runtime\Http\ResponseHandler.cs:186
at Unity.Services.Lobbies.Apis.Lobby.LobbyApiClient.CreateLobbyAsync (Unity.Services.Lobbies.Lobby.CreateLobbyRequest request, Unity.Services.Lobbies.Configuration operationConfiguration) [0x0011f] in C:\Unity Projects\Table Top Racers\Library\PackageCache\com.unity.services.lobby@1.0.0-pre.6\Runtime\Apis\LobbyApi.cs:224
at Unity.Services.Lobbies.WrappedLobbyService.TryCatchRequest[TRequest,TReturn] (System.Func3[T1,T2,TResult] func, TRequest request) [0x0003a] in C:\Unity Projects\Table Top Racers\Library\PackageCache\com.unity.services.lobby@1.0.0-pre.6\Runtime\SDK\WrappedLobbyService.cs:194 --- End of inner exception stack trace --- at Unity.Services.Lobbies.WrappedLobbyService.ResolveErrorWrapping (Unity.Services.Lobbies.LobbyExceptionReason reason, System.Exception exception) [0x00032] in C:\Unity Projects\Table Top Racers\Library\PackageCache\com.unity.services.lobby@1.0.0-pre.6\Runtime\SDK\WrappedLobbyService.cs:249 at Unity.Services.Lobbies.WrappedLobbyService.TryCatchRequest[TRequest,TReturn] (System.Func
3[T1,T2,TResult] func, TRequest request) [0x0011f] in C:\Unity Projects\Table Top Racers\Library\PackageCache\com.unity.services.lobby@1.0.0-pre.6\Runtime\SDK\WrappedLobbyService.cs:221
at Unity.Services.Lobbies.WrappedLobbyService.CreateLobbyAsync (System.String lobbyName, System.Int32 maxPlayers, Unity.Services.Lobbies.CreateLobbyOptions options) [0x00098] in C:\Unity Projects\Table Top Racers\Library\PackageCache\com.unity.services.lobby@1.0.0-pre.6\Runtime\SDK\WrappedLobbyService.cs:39
at LobbyManager.Start () [0x0011b] in C:\Unity Projects\Table Top Racers\Assets\Scripts\LobbyManager.cs:39
UnityEngine.Debug:LogError (object)
LobbyManager/d__1:MoveNext () (at Assets/Scripts/LobbyManager.cs:44)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder1<Unity.Services.Lobbies.Models.Lobby>:SetException (System.Exception) Unity.Services.Lobbies.WrappedLobbyService/<CreateLobbyAsync>d__4:MoveNext () (at Library/PackageCache/com.unity.services.lobby@1.0.0-pre.6/Runtime/SDK/WrappedLobbyService.cs:40) System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1<Unity.Services.Lobbies.Response1<Unity.Services.Lobbies.Models.Lobby>>:SetException (System.Exception) Unity.Services.Lobbies.WrappedLobbyService/<TryCatchRequest>d__18
2<Unity.Services.Lobbies.Lobby.CreateLobbyRequest, Unity.Services.Lobbies.Models.Lobby>:MoveNext () (at Library/PackageCache/com.unity.services.lobby@1.0.0-pre.6/Runtime/SDK/WrappedLobbyService.cs:228)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder1<Unity.Services.Lobbies.Response
1<Unity.Services.Lobbies.Models.Lobby>>:SetException (System.Exception)
Unity.Services.Lobbies.Apis.Lobby.LobbyApiClient/d__6:MoveNext () (at Library/PackageCache/com.unity.services.lobby@1.0.0-pre.6/Runtime/Apis/LobbyApi.cs:225)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse) Unity.Services.Lobbies.Http.HttpClient/<MakeRequestAsync>d__3:MoveNext () (at Library/PackageCache/com.unity.services.lobby@1.0.0-pre.6/Runtime/Http/HttpClient.cs:47) System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse)
Unity.Services.Lobbies.Http.HttpClient/d__7:MoveNext () (at Library/PackageCache/com.unity.services.lobby@1.0.0-pre.6/Runtime/Http/HttpClient.cs:138)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse) Unity.Services.Lobbies.Http.HttpClient/<>c__DisplayClass7_0/<<CreateWebRequestAsync>b__0>d:MoveNext () (at Library/PackageCache/com.unity.services.lobby@1.0.0-pre.6/Runtime/Http/HttpClient.cs:135) System.Threading.Tasks.TaskCompletionSource
1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse)
Unity.Services.Lobbies.Http.UnityWebRequestHelpers/<>c__DisplayClass0_0:b__0 (UnityEngine.AsyncOperation) (at Library/PackageCache/com.unity.services.lobby@1.0.0-pre.6/Runtime/Http/UnityWebRequestHelpers.cs:34)
UnityEngine.AsyncOperation:InvokeCompletionEvent ()