Firebase Realtime Database Emulator and Unity

Hi,

Just a shot in the dark here but I was wondering if anyone has any experience getting Unity to work with Firebase emulators, specifically the Realtime Database emulator. Not much information out there. I haven’t had much luck.

Thanks in advance.

I got this to work, some tips:

  1. Change the database in your googleservices json files to http:127.0.0.1:9000
  2. If you’re loading in the data from somewhere else (i.e. a python script) use the namespace “ns=127”.
1 Like

I’ve tried you suggestion. I can add data to the emulator. However, I found it created a new database (http://localhost:9000/?ns=127) instead of my existing one (http://localhost:9000/?ns=abc) as attached. I used cloud function the manage the existing database (http://localhost:9000/?ns=abc). Do you think how could I fix it? Thanks for your help in advance.

It looks I fixed the problem. I added the following in the cloud function.

let config = {
databaseURL :‘http://127.0.0.1:9000/?ns=127
}

admin.initializeApp(config)

I changed the firebase_url to http://localhost:9000/, is there anything else I’m missing? Even with this change the database is still writing to the remote project and not the emulator.

With this change, I am getting the ns=127 db in the emulator dashboard, but all SetValueAsyncs are being set in the remote db and not this local db.

Ugh I was editing the wrong googleservices file (wrong project). This does work. Thanks!

Hi,
i changed the google-services.json file like this

but I always get this error:

Firebase.Database.DatabaseException: Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your GetInstance() call.
at Firebase.Database.FirebaseDatabase.GetInstance (Firebase.FirebaseApp app, System.String url) [0x0000b] in Z:\tmp\tmp.EaZAfBKdnh\firebase\database\client\unity\proxy\FirebaseDatabase.cs:150

Can you help me?
Thank you

Hi @discovertravelrelax , did you fix this?

The solution is simple. After creating database on firebase console download the updated configuration files and replace with old configuration files in unity project.
Firebase