Open Awais6 opened 2 weeks ago
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Hey @Awais6, thanks for reaching out. I tried reproducing this behavior with our quickstart, and so far I'm not encountering any issues. That said, could you answer a few questions below so I can investigate this further?
Invoke GoOffline from firebaseDatabase instance inside OnApplicationQuit(). FirebaseDatabase should be connected and in use (like you can join any active listener on some node)
I understand that FirebaseDatabase can add active listeners, however, based on your comment, are you expecting the FirebaseDatabase
to work even after invoking GoOffline
?
GoOffline
in the OnApplicationQuit
? Is there particular reason why you manually have to call this? From my understanding, there is already an automatic disconnection once the app closes.Hi @argzdev, thanks for the quick response.
I am develping a multiplayer networking system with firebase database. Players create/join the room and pass data to each other in the room. i am using firebase database OnDisconnect.SetValue
to set player's connectivity status as disconnected when there is a network problem.
When i use GoOffline()
inside unity's OnApplicationQuit()
, if any user minimize the game and clear it from recents on Android. GoOffline()
is fired and OnDisconnect.Setvalue
works instantly.
Otherwise, If i don't use GoOffline()
in unity's OnApplicationQuit()
firebase servers detects player's network disconnection too late (after 60s to 90seconds).
Is GoOffline()
automatically called, when User minimize the game/app and clear recent apps on Android?
Hey @Awais6, thanks for the extra details. No, GoOffline()
does not automatically call. I initially thought, you're only using GoOffline
closing the app via OnApplicationQuit
, I didn't take into account that you also consider minimizing the app.
There's a caveat in using OnApplicationQuit:
Warning: If the user suspends your application on a mobile platform, the operating system can quit the application to free up resources. In this case, depending on the operating system, Unity might be unable to call this method. On mobile platforms, it is best practice to not rely on this method to save the state of your application.
I believe using OnApplicationPause is a better way of handling this types of scenario for your use case.
Let me know if this helps. Thanks!
Hi @argzdev, Ok, I will try and reply back.
Description
Firebase sometimes throws NullReferenceException when we call GoOffline from Unity's OnApplicationQuit() in UnityEditor 2021.3.38f1 LTS.
I am using FirebaseAuth, FirebaseDatabase, FirebaseFirestore, FirebaseFunctions, FirebaseAnalyics
Reproducing the issue
Invoke GoOffline from firebaseDatabase instance inside OnApplicationQuit(). FirebaseDatabase should be connected and in use (like you can join any active listener on some node)
Firebase Unity SDK Version
11.9.0
Unity editor version
2021.3.38f1 LTS
Installation Method
.unitypackage
Problematic Firebase Component(s)
Database
Other Firebase Component(s) in use
Analytics, Authentication, Crashlytics, Database, Firestore, Functions
Additional SDKs you are using
UnityAds
Targeted Platform(s)
Android
Unity editor platform
Windows
Scripting Runtime
IL2CPP
Release Distribution Type
Pre-built SDK from https://firebase.google.com/download/unity
Relevant Log Output
If using CocoaPods for Apple platforms, the project's Podfile.lock
Expand
Podfile.lock
snippet```yml 👀 Podfile.lock not needed, i am using Windows. ```