This is my first time using Firebase with Unity. My code seems to be connected to my Firestore database but is not retrieving the data.
I also get this error message: System.Threading.Tasks.ContinuationResultTaskFromResultTask2[Firebase.Firestore.DocumentSnapshotProxy,Firebase.Firestore.DocumentSnapshot] UnityEngine.Debug:Log(Object) <>c:<savedata>b__5_0(Task1) (at Assets/Scripts/CloudFirebase.cs:60)
The corresponding line for CloudFirebase.cs:60 is Debug.Log(task); and the code normally gets stuck on is line DocumentSnapshot snapshot = task.Result;
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback()
Note: I have tried to look around for answers relating to my issue but can't seem to find any. If you have any links that relate specifically to Unity please do share. Here's my code below:
FirebaseFirestore db;
Dictionary<string, object> user;
CollectionReference stuRef;
private bool istrue = true;
// Start is called before the first frame update
void Start()
{
Debug.Log("Start called");
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
var dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available)
{
Debug.Log("available for use");
// Create and hold a reference to your FirebaseApp,
// where app is a Firebase.FirebaseApp property of your application class.
//app = Firebase.FirebaseApp.DefaultInstance;
db = FirebaseFirestore.DefaultInstance;
Debug.Log(db.Collection("Users").Document("hello"));
stuRef = db.Collection("Users");
savedata();
// Set a flag here to indicate whether Firebase is ready to use by your app.
}
else
{
UnityEngine.Debug.LogError(System.String.Format(
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
// Firebase Unity SDK is not safe to use here.
}
});
//db = FirebaseFirestore.DefaultInstance;
//if (istrue)
//{
// savedata();
// istrue = false;
//}
}
public void savedata()
{
stuRef.Document("hello").GetSnapshotAsync().ContinueWith(task =>
{
if (task.IsCompleted)
{
task.GetAwaiter();
if (task.IsFaulted)
{
Debug.Log(task.Exception.Message);
}
Debug.Log("succesfully added to database");
Debug.Log(task);
DocumentSnapshot snapshot = task.Result;
if (snapshot.Exists)
{
Debug.Log("snapshot exists");
//user = snapshot.ToDictionary();
// foreach (KeyValuePair<string, object> pair in user)
// {
// Debug.Log(("{0}:{1}", pair.Key, pair.Value));
// }
}
else
{
Debug.Log("snapshot does not exist");
}
}
else
{
Debug.Log("failed db");
}
});
}