quickstart-unity icon indicating copy to clipboard operation
quickstart-unity copied to clipboard

[FR][Database] Support connection to local Firebase emulator (Android/iOS/desktop)

Open nhutthanh340 opened this issue 4 years ago • 6 comments

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2020.1.9 personal
  • Firebase Unity SDK version: 6.15.2
  • Source you installed the SDK: 6.15.2 (.unitypackage or Unity Package Manager)
  • Problematic Firebase Component: firebase databse realtime (Auth, Database, etc.)
  • Other Firebase Components in use: firestore, functions(Auth, Database, etc.)
  • Additional SDKs you are using: none (Facebook, AdMob, etc.)
  • Platform you are using the Unity editor on: windows (Mac, Windows, or Linux)
  • Platform you are targeting: iOS, Android, desktop (iOS, Android, and/or desktop)
  • Scripting Runtime: Mono (Mono, and/or IL2CPP)

[REQUIRED] Please describe the issue here:

(Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.)

Steps to reproduce:

Hi, I'm currently having a problem with the value change listening event in Unity. I use Firebase emulator locally. I just get the snapshot with null value. Can you help me solve this problem. Thanks.

99405483-65963580-291f-11eb-8a93-3442adb486d8 99405328-38e21e00-291f-11eb-9690-3ec9bd84eeeb

This code is working when I use firebase database realtime on cloud.

nhutthanh340 avatar Nov 17 '20 23:11 nhutthanh340

+1 to this one, I've been trying a bunch of different tricks with no luck trying to get this to work for the past two months... tempted to roll my own client that leverages the REST API instead just to get past this hurdle. :/

animanmaster avatar Nov 18 '20 04:11 animanmaster

@nhutthanh340 Just to confirm, the issue only happen when you run in editor, correct?

Taking a look of the documentation, it requires some special API like database.useEmulator("10.0.2.2", 9000); in order to connect to an emulator. And unfortunately this API is not available in C++/Unity SDK yet.

Let me change this to a feature request. If you are interested in seeing this feature, please upvote the first post to let us know.

chkuang-g avatar Nov 25 '20 05:11 chkuang-g

I updated the firebase.database sdk to 7.0 and changed the "firebase_url" in both google-services.json and google-services-desktop.json. I can write data to the emulator database. However, it created another database (http://localhost:9000/?ns=127) instead of my original database(http://localhost:9000/?ns=abc). I don't know why.

redkoda avatar Dec 03 '20 10:12 redkoda

I have the same issue, it seems when you set the Instance to your localhost, it doesnt accept the name space, and created a new database with the name 'localhost' #if UNITY_EDITOR return FirebaseDatabase.GetInstance("http://localhost:9000?ns=project-id"); #else return FirebaseDatabase.DefaultInstance; #endif

Bigboer avatar Dec 18 '20 13:12 Bigboer

I also have the same issue when I tried to connect my Unity project to emulator database. It connected to wrong namespace. Please fix

mryakhont avatar Sep 06 '21 10:09 mryakhont

This feature will also enable unit testing of database functionality. See: https://stackoverflow.com/questions/69126781/how-do-you-write-integration-tests-for-firestore-on-unity

I have upvoted the original post, and I'm hoping it can be prioritized by the Firebase team. 🙏

artoonie avatar Sep 14 '21 19:09 artoonie