Using Firebase SDK in Unity and when I am trying to make a simple leaderboard for a group of three mingames I made. The problem I am having is accessing the database using GetValueAsync() and ContinueWith() it seems to completely skip ContinueWith() everytime. Here is my code:
string scoreDisplay(string game, string pos)
{
FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://shape-arcade-leaderboard.firebaseio.com/");
string score = "error";
FirebaseDatabase.DefaultInstance.RootReference.GetValueAsync().ContinueWith(task =>
{
if (task.IsCompleted)
{
DataSnapshot data = task.Result;
score = data.Child("scores").Child(game).Child(pos).Value.ToString();
return score;
}
else if (task.IsFaulted)
{
score = "errorfaulted";
return score;
}
else
{
return score;
}
});
return null;
}
So the function is taking in the name of the relevant minigame and the position child from which the data is to be retrieved. It is trying to access my database and pull down a snapshot of it at which point it should enter the ContinueWith() function. Then if completed it should access the database and the relevant child game and then the child position within that game and return its value. If faulted it should just return "errorfaulted", else it should just return "error". However, instead, it is just returning null at the bottom as it never seems to run ContinueWith().
I am aware a similar question was raised at Stack Overflow Question but it does not seem to have an answer other than wait for the next beta release and then the suggested work around. The work arounds haven't seemed to work for me either - I tried indexing the database and making sure there is data across it but it made no difference. Anyway I hope someone can help me, I would be so grateful!