var scoreResponse = await LeaderboardsService.Instance.AddPlayerScoreAsync( LeaderboardId, 22 );
Gives me scoreResponse == null
Now if I change LeaderboardId to something bogus I Get HttpException`1: (404) HTTP/1.1 404 Not Found
thus LeaderboardId is correct so why does it return null?
My first thought is I’m not signed in but I do
await AuthenticationService.Instance.SignInAnonymouslyAsync();
print( “Sign in anonymously succeeded! Player Id:” + AuthenticationService.Instance.PlayerId );
givesme
Player Id:MiX9qkotw38kbLTk1PO00n8lTe8w
thus I assume that worked
There’s a Leaderboards SDK Sample that covers most of the basic use cases here, which includes service initialization, authenticating and serializing response objects as well as links to creating your leaderboard on the Unity Cloud Dashboard.
If you still have issues can you post a complete sample of what you’re doing and I’ll have a look into it?
Though of course perhaps the doc’s forgot to mention that it can return null if something went wrong, so my question is what can cause it to return that?
EDIT: To make it clear I am doing the SDK example thus I assume the problem lies elsewhere, I’ve checked everything but are not sure where the problem lies
Hmmm Jsonconvert? It returns a Task which isn’t a json string.
Try: Debug.Log(scoreResponse);
Be sure to enclose these calls in try/catch exception handling, even while doing tests. Service calls WILL fail one way or another, ie user loses Internet connection.
Cheers mate, I’m not 100% sure what you mean WRT json string
like I said scoreResponse == null ← that is the problem, why is it returning null, i.e. whats causing it to fail?
the above code is from the Unity Script Example.
I assume the example code is correct
My brain is failing me I’ve been stuck on this 2 days now, and are getting dumber each minute.
Ideally I would just roll my own online database (as I’ve done many times over the years in SQL but due to lack of budget I don’t have access to that, I even couldn’t afford the amazon free database trial yesterday, haha )
EDIT: Wait a sec, now its not null, huh! I’ll dig into this some more
I agree with CodeSmile, wrapping it up in a try-catch block could provide more insights and could be expanded to add some resiliency down the line.
Even just something like this for now:
public async void AddScore()
{
try
{
var scoreResponse = await LeaderboardsService.Instance.AddPlayerScoreAsync(LeaderboardId, 102);
if (scoreResponse == null)
{
// To confirm I think it's much more likely to be an exception than ever get to this line
Debug.LogError("Score response is null.");
}
else
{
Debug.Log(JsonConvert.SerializeObject(scoreResponse));
}
}
catch (Exception ex)
{
Debug.LogError($"An error occurred: {ex.Message}");
}
}
Regarding the null responses, I’ve reviewed the SDK implementation, and it seems that every response or failure from the leaderboards service should be encapsulated in a response object.
But if you say that’s impossible, well I suppose you’re right.
Yes good advice with the try/catch thing, even though I’m quite a big logger, I rarely use try/catches. Though I suppose here is a good place as like CodeSmile said, Internet is not 100% guaranteed.
I’ll have another look tomorrow once I’ve rested. In trying to solve this I updated my Steamworks Version and now my old code doesn’t work as some of the functions I was using don’t work now eg SignInWithSteamAsync()
FWIW I did sorta implement it here,
Though not fully as #1 I couldn’t get the authentication to work fully ( even though its installed I can’t seem to update it, but all good, never mind, also I wanna let the person write their own sig each time ) #2 I’m wanting to do more with the leaderboard eg perhaps top 5 scores per person on each of the 4 scenes. I just think SQL is a better fit for my purpose as it’s more flexible (yes it’s more difficult to use but I’ve used that a lot in the past, I had a horror film site like IMDB a long time ago, so know my way around DB languages)
If you’re curious there’s a demo here