Can't set firebase realtime database reference

Viewed 9

From my Unity app, I can create accounts and sign in to them but I can't write or read a data from firebase.

For example, this line gives me error "null reference exception"

var DBTask = DBreference.Child("users").Child(User.UserId).Child("username").SetValueAsync(_username);

So I tried to find where the problem is, and I tried to print a message after database reference, but Unity never prints the message. Am I doing something wrong when creating DBreference?

  void Awake()
{
    
    FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
    {
        dependencyStatus = task.Result;
        if (dependencyStatus == DependencyStatus.Available)
        {
            
            InitializeFirebase();
        }
        else
        {
            
        }
    });
}

private void InitializeFirebase()
{
    auth = FirebaseAuth.DefaultInstance;

    DBreference = FirebaseDatabase.DefaultInstance.RootReference;

    Debug.Log("Done!");
}
1 Answers

For anyone who faces with this problem, I added this line to google-services.json. Everything works fine now.

"firebase_url": "MY DB URL"
Related