Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase - Offline behaviour for Unity

I recently started working on my game using Firebase and considering what Firebase offers is pretty much all I need, at one place. But now i'm facing few limitations/implementation issues so any help would be appreciated.

I'm developing a semi-online game which will allow users to play as long as no network is available and sync with Firebase soon as it gets connected. For very first launch connection is mandatory as i've to pull configuration data from Firebase and later user can play with offline saved state which will be pushed later whenever connected.

I'm quite noob to Firebase so pardon me if I misunderstood any implementation. I looked over different answers and mostly were in respect to native Android/iOS, not for Unity. So either I wasn't able to find my answer or it was asked years ago but still not answered. Thanks!

like image 779
Aman Ullah Avatar asked Apr 06 '17 10:04

Aman Ullah


2 Answers

Disk persistence for the Realtime Database is now available since version 5.4.0 of the Firebase SDK for Unity. See the documentation for FirebaseDatabase. SetPersistenceEnabled() and the release notes for that version.

like image 187
Frank van Puffelen Avatar answered Nov 15 '22 08:11

Frank van Puffelen


Old question but still hard to find a correct answer. Firebase documentation is definitively ambiguous : on this page : https://firebase.google.com/docs/database/unity/start First lines : "The Firebase Realtime Database stores and synchronizes data with our NoSQL cloud database. Data is synced across all clients in realtime, and remains available when your app goes offline."

Unity Firebase does not support real offline capabilities. It will work only if your game starts with a network ON, and while playing, if the player has network OFF, it will go on correctly as long as you have the network ON before stopping the game ! so it can synchronize.. otherwise all changes are lost !

Here is a answer coming from the firebase support on this problem :

Currently, Unity doesn't support offline capability. Apologies about this. This is indeed something we're looking into, however, I cannot guarantee that this will be available anytime soon. We'll keep your feedback in consideration moving forward.

The documentation is explaining that your app will continue to save your data while offline. When data is written, it's written to this local version first and synchronizes that data to the server once connectivity is reestablished. Check here for more details. For additional context, Firebase's network resilience will work on Unity. So as long as the app stays active, Firebase will continue functioning if the network connection drops. In that case it serves any reads from its cache and keeps a queue of pending writes. But currently there is no support for disk persistence, which would allow the cache and queue to survive during app restarts.

like image 28
Julien Revault d'A... Avatar answered Nov 15 '22 07:11

Julien Revault d'A...