I am attempting to pull data from my Realtime Database in Firebase and then put that string into a TMP_Text field in unity.
There seems to be an issue with writing to a text field while within the .ContinueWith(task => portion of my code. While inside the task.isCompleted I can get the snapshot print the value after converting it to string, however, as soon as I try to write to the text field the code haults. In the example below the output is as follows.
- Prints the snapshot, both key and value
- Prints the value of the snapshot as a string
- No errors no thing happens
- The 4th print of Value does not print at all
public void PopulateScoreBoard()
{
FirebaseDatabase.DefaultInstance.GetReference("userlist").Child(LoadingScreen.userID).Child("score").GetValueAsync().ContinueWith(task =>
{
if (task.IsFaulted)
{
//handle error
scoreboard.text = "Error!";
}
else if (task.IsCompleted)
{
//get snapshot fo data
DataSnapshot snapshot = task.Result;
print(snapshot);
print(snapshot.Value.ToString());
//Get the scoreboard value within the result snapshot
scoreboard.text = snapshot.Value.ToString();
//print the same value to ensure it is working
print(snapshot.Value.ToString());
}
});
}
Looking forward to getting some input, I'm assuming there is some reason you cannot write to anything in this, however, I cannot find it. If this is the case what is my alternative?
*Update: It seems as though after further testing you cannot set anything equal to anything inside the ContinueWith(task => is that normal?