firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
822 stars 425 forks source link

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

Open nhutthanh340 opened 3 years ago

nhutthanh340 commented 3 years ago

[REQUIRED] Please fill in the following fields:

[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.

animanmaster commented 3 years ago

+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. :/

chkuang-g commented 3 years ago

@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.

redkoda commented 3 years ago

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.

Bigboer commented 3 years ago

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

mryakhont commented 2 years ago

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

artoonie commented 2 years ago

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. 🙏