0

You want to use the real-time database functionality of Google Firebase. You have followed the guide page to complete all of them.

I also downloaded the Google-services file. The Firebase SDK installation is also complete.

I also created a database from the Firebase console.

My code is so simple because I was just testing it.

public class FirebaseManager : MonoBehaviour
{
 
    DatabaseReference fbRef;
    void Start(){
       fbRef = FirebaseDatabase.DefaultInstance.RootReference;
    }
}

what's wrong with FirebaseDatabase.DefaultInstance.RootReference; ??

enter image description here

I've redownloaded the google-service.json file and added "firebase_url" : "https://gamename-default-rtdb.firebaseio.com/" this line to project_info in google-services.json.

and I added these 2 lines to mainTemplate.gradle (Assets/Plugins/Android/mainTemplate.gradle)

    implementation platform('com.google.firebase:firebase-bom:26.3.0')
    implementation 'com.google.firebase:firebase-database-ktx'

but nothing changed.

Haseyo
  • 1
  • 2
  • [This](https://stackoverflow.com/questions/66163922/how-to-set-firebase-database-url-unity) question might be able to help you, since the issue lies in the firebase_url not being read properly. – Velorexe Mar 08 '23 at 09:32
  • @Velorexe I checked that question and downloaded config files again but still same. but still thank you! – Haseyo Mar 08 '23 at 17:54

1 Answers1

0

Instead of using

fbRef = FirebaseDatabase.DefaultInstance.RootReference;

try using

const string url = "https://gamename-default-rtdb.firebaseio.com/";
fbRef = FirebaseDatabase.GetInstance(url).RootReference;

This directly calls a function shown in your screenshot that is currently being passed a null or empty string. If this works the issue is that something about passing the url from the json file is not going through properly (which could result from formatting or building for the wrong build target or any number of things).

Joe Spiro
  • 89
  • 3