Hi, I am trying to create an event listener to my firebase query script but it acts a little strange?!?
Here is my script:
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using UnityEngine.Events;
using Firebase.Firestore;
public class TestDataHandler : MonoBehaviour
{
public GameObject testObject;
private void Start()
{
fbEvent.AddListener(readyToGo);
GetUserData("12345");
}
void readyToGo()
{
Debug.Log("Do Stuff");
tetsObject.SetActive(false);
Debug.Log("Stuff Done");
}
UnityEvent fbEvent = new UnityEvent();
public void GetUserData(string userId)
{
Query query = FirebaseDataManager.instance.users
.WhereEqualTo("userId", userId
);
query.GetSnapshotAsync().ContinueWith(querySnapshotTask =>
{
if (querySnapshotTask.IsFaulted)
{
Debug.Log("No userdata is found");
}
else if (querySnapshotTask.Result.Documents.Count() < 1)
{
Debug.Log("No userdata is found");
}
else
{
DocumentSnapshot userData = querySnapshotTask.Result.Documents.FirstOrDefault();
Dictionary<string, object> data = userData.ToDictionary();
User tempUser = FirebaseSerializer.FBDataToObject(data) as User;
Debug.Log("Userdata found: " + tempUser.firstName);
fbEvent.Invoke();
}
});
}
}
It kinda works, course the listener listens but I am not able to, in this example, to deactivate an gameobject from the listener return function.
I get the “Do Stuff” log, but not the “Stuff Done” log and the GameObject is not deactivated?
What am I missing here?!?! Really hoping for help and thanks in advance