Home > Blockchain >  Unity Firebase SDK Gives an DatabaseException when initilazing DatabaseReference
Unity Firebase SDK Gives an DatabaseException when initilazing DatabaseReference

Time:02-03

I've installed Unity Firebase SDK, firebase google-services and configured Player Settings with com project name. After that, I've written the following lines of code:

private DatabaseReference _databaseReference;
    private string _userID;

    private void Start()
    {
        _databaseReference = FirebaseDatabase.DefaultInstance.RootReference;
        _userID = SystemInfo.deviceUniqueIdentifier;
    }

Even though I followed the steps from the official documentation, I got an error:

DatabaseException: Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your GetInstance() call. Firebase.Database.FirebaseDatabase.GetInstance (Firebase.FirebaseApp app, System.String url)

Can someone help me please?

I've also tried adding FirebaseDatabase.GetInstance() but I get an error:

DatabaseException: Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your GetInstance() call. Firebase.Database.FirebaseDatabase.GetInstance

CodePudding user response:

It looks like the Google-Service-info.plist or GoogleServices.json file that you're using doesn't include the correct database URL.

So work around that, specify the URL of the database in your GetInstance call:

_databaseReference = FirebaseDatabase.GetInstance("your database URL here").RootReference;

You can find the URL in the Firebase console for your database.

  • Related