Hello there !
been trying to implement Unity Leaderboard in my project ( unity v. 2022.3.28f1 ), but keep failing whenever i call the AddPlayerScoreAsync function.
i do authenticate the player via SignInAnonymouslyAsync function and everything works fine ( i checked the user login in my dashboard and ids matched ).
here’s the code:
public class OnlineManager : MonoBehaviour
{
public string leaderboardId = "tlo_1_1";
public static OnlineManager Instance;
private async void Awake()
{
var options = new InitializationOptions();
options.SetEnvironmentName("production");
await UnityServices.InitializeAsync(options);
await signiIn();
if (Instance != null)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
}
private async Task signiIn()
{
AuthenticationService.Instance.SignedIn += OnSignedIn;
AuthenticationService.Instance.SignInFailed += OnSignInFailed;
Debug.Log("Signing in...");
await AuthenticationService.Instance.SignInAnonymouslyAsync();
}
private void OnSignedIn()
{
Debug.Log($"Signed in as: {AuthenticationService.Instance.PlayerId}");
}
private void OnSignInFailed(RequestFailedException exception)
{
Debug.Log($"Sign in failed with exception: {exception}");
}
public async void SubmitScoreAsync()
{
try
{
var scoreResponse = await LeaderboardsService.Instance.AddPlayerScoreAsync(leaderboardId, 100/*score*/ );
//messageText.text = "Score submitted!";
Debug.Log("Score submitted!"+ scoreResponse);
}
catch (Exception e)
{
//messageText.text = $"Failed to submit score: {e}";
Debug.Log($"Failed to submit score: {e}");
throw;
}
}
so…
- the user gets authenticated.
- the project-id is correct ( i doublechecked this comparing the id i find on the dashboard and the id i find in edit → project settings → Services )
- the environment name is correct ( i also created a new environment, named it “dev”, created another leaderboard in it and “called” it via InitializationOptions passed in UnityServices.InitializeAsync function, still nothing changed )
- the leaderboard id is correct
here’s the error output in console:
HttpException1: (404) HTTP/1.1 404 Not Found Unity.Services.Leaderboards.Internal.Http.ResponseHandler.HandleAsyncResponse (Unity.Services.Leaderboards.Internal.Http.HttpClientResponse response, System.Collections.Generic.Dictionary
2[TKey,TValue] statusCodeToTypeMap) (at ./Library/PackageCache/com.unity.services.leaderboards@2.1.0/Runtime/com.unity.services.leaderboards.internal/Http/ResponseHandler.cs:112)
Unity.Services.Leaderboards.Internal.Http.ResponseHandler.HandleAsyncResponse[T] (Unity.Services.Leaderboards.Internal.Http.HttpClientResponse response, System.Collections.Generic.Dictionary2[TKey,TValue] statusCodeToTypeMap) (at ./Library/PackageCache/com.unity.services.leaderboards@2.1.0/Runtime/com.unity.services.leaderboards.internal/Http/ResponseHandler.cs:216) Unity.Services.Leaderboards.Internal.Apis.Leaderboards.InternalLeaderboardsApiClient.AddLeaderboardPlayerScoreAsync (Unity.Services.Leaderboards.Internal.Leaderboards.AddLeaderboardPlayerScoreRequest request, Unity.Services.Leaderboards.Internal.Configuration operationConfiguration) (at ./Library/PackageCache/com.unity.services.leaderboards@2.1.0/Runtime/com.unity.services.leaderboards.internal/Apis/InternalLeaderboardsApi.cs:204) Unity.Services.Leaderboards.Internal.LeaderboardsServiceInternal+<>c__DisplayClass3_0.<AddPlayerScoreAsync>g__AddPlayerScoreAsyncInternal|0 () (at ./Library/PackageCache/com.unity.services.leaderboards@2.1.0/Runtime/com.unity.services.leaderboards.internal/LeaderboardsServiceInternal.cs:38) Unity.Services.Leaderboards.Internal.LeaderboardsServiceInternal.RunWithErrorHandling (System.Func
1[TResult] method) (at ./Library/PackageCache/com.unity.services.leaderboards@2.1.0/Runtime/com.unity.services.leaderboards.internal/LeaderboardsServiceInternal.cs:213)
Rethrow as LeaderboardsException: Leaderboard config could not be found
Unity.Services.Leaderboards.Internal.LeaderboardsServiceInternal.RunWithErrorHandling (System.Func`1[TResult] method) (at ./Library/PackageCache/com.unity.services.leaderboards@2.1.0/Runtime/com.unity.services.leaderboards.internal/LeaderboardsServiceInternal.cs:221)
Unity.Services.Leaderboards.Internal.LeaderboardsServiceInternal.AddPlayerScoreAsync (System.String leaderboardId, System.Double score, Unity.Services.Leaderboards.AddPlayerScoreOptions options) (at ./Library/PackageCache/com.unity.services.leaderboards@2.1.0/Runtime/com.unity.services.leaderboards.internal/LeaderboardsServiceInternal.cs:42)
OnlineManager.SubmitScoreAsync () (at Assets/Scripts/OnlineManager.cs:102)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) (at :0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <55fbbbd17b724c15b6abe8c1a3e3289c>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <55fbbbd17b724c15b6abe8c1a3e3289c>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <55fbbbd17b724c15b6abe8c1a3e3289c>:0)
thank u so much !