Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Firebase Realtime Database Emulator and Unity

Discussion in 'Multiplayer' started by tmfconan, May 5, 2020.

  1. tmfconan

    tmfconan

    Joined:
    Oct 16, 2017
    Posts:
    8
    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.
     
  2. tmfconan

    tmfconan

    Joined:
    Oct 16, 2017
    Posts:
    8
    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".
     
    paulyip likes this.
  3. paulyip

    paulyip

    Joined:
    Oct 9, 2018
    Posts:
    2

    Attached Files:

  4. paulyip

    paulyip

    Joined:
    Oct 9, 2018
    Posts:
    2
    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)
     
  5. RabitLabs

    RabitLabs

    Joined:
    Jul 20, 2021
    Posts:
    2
    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.
     
  6. RabitLabs

    RabitLabs

    Joined:
    Jul 20, 2021
    Posts:
    2
    Ugh I was editing the wrong googleservices file (wrong project). This does work. Thanks!
     
  7. discovertravelrelax

    discovertravelrelax

    Joined:
    Jan 6, 2022
    Posts:
    3
    Hi,
    i changed the google-services.json file like this

    upload_2022-1-6_16-57-29.png

    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