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

Question Is Firestore offline data persistence supported in Unity?

Discussion in 'Editor & General Support' started by Kamelic, Jul 29, 2022.

  1. Kamelic

    Kamelic

    Joined:
    Jan 30, 2020
    Posts:
    4
    According to the Firestore documentation related to offline data persistence, there seems to be little (or contradictory) information on whether the feature is actually supported in Unity.

    https://firebase.google.com/docs/firestore/manage-data/enable-offline "Offline persistence is supported only in Android, Apple, and web apps." Which I interpret as that it is not supported in Unity.

    Based on this official Firebase tutorial it would seem that offline persistence is supported? (12:00 onwards)

    Basically I would like to know if it is possible for my users to lose internet connection while playing and the Firestore SDK would handle caching the sent data and update it to the Firestore database when there is connection available, whether it is within the same session or the next. I am currently conducting some tests on some devices whether it works this way or not.

    I'll gladly hear if any of you has had any experience regarding this feature.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    I don't see a contradiction in the docs you shared. Unity can be used to make Android, iOS and web apps. Therefore you can use this firebase feature in Unity games published on those platforms, but not other platforms that Unity supports.
     
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,184
  4. Kamelic

    Kamelic

    Joined:
    Jan 30, 2020
    Posts:
    4
    This most likely is the correct way to interpret this. The lack of code examples in Unity and C# just made me unsure about the feature being supported in Unity. Also at some portions of the documentation and code examples regarding offline persistence, there was a mention "This is not yet supported in the Unity SDK".
     
  5. Kamelic

    Kamelic

    Joined:
    Jan 30, 2020
    Posts:
    4
  6. Kamelic

    Kamelic

    Joined:
    Jan 30, 2020
    Posts:
    4
    I did some tests on my Android 12 device. And it would seem that Offline persistence is enabled! I tested it by doing the following actions:

    • Open my Unity game while having internet connection
    • Disable internet connection and send data
    • Close the game, enable internet connection and open the game
    • The data was sent to Firestore

    This works even if the phone is rebooted.

    Currently I am wondering if there is a way to know when the Offline Persistence is being used. Like an event when the data was successfully sent to Firestore. Currently it is a magical black box for me which updates the data to Firebase when it wants.

    I know that I can use Listeners to check for updates in certain document changes.