Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Keeping Android save data between updates on Google Play with persistantDataPath

Discussion in 'Android' started by Sudden62, Aug 30, 2021.

  1. Sudden62

    Sudden62

    Joined:
    May 3, 2017
    Posts:
    11
    Hello, I've run into an issue with losing save data after updating my app on Google Play.

    The problem is that Application.persistantDataPath supposedly points to a different location based on the Build Number (versionCode) of the app. I can't keep the build number the same, because the Google Play Console will reject it.

    From the Unity Docs: "When you build the Unity application, a GUID is generated that is based on the Bundle Identifier. This GUID is part of persistentDataPath. If you keep the same Bundle Identifier in future versions, the application keeps accessing the same location on every update."

    Since I can't keep the Build number the same, it seems I need to abandon persistantDataPath so users can keep their data. If so, I'll detect an Android build and use a static location. I do worry about having to ask the user for File Permissions when not necessary, though.

    But now as I look into using a static location, I've become rather confused. Android's persistantDataPath: "/storage/emulated/0/Android/data/<packagename>/files"
    does not contain the Build Number... So how does it manage to point to different locations?

    Next, I ran a test where I updated my app with a newer build number, and the save files were still there! However, I recall that I did in fact lose the save data when the update came through Google Play.

    So all this is to say, does anyone have experience with this and could possibly share some insight?
    Thank you for reading.
     
  2. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    835
  3. Sudden62

    Sudden62

    Joined:
    May 3, 2017
    Posts:
    11
    Ah, that makes sense. Since posting I had an update approved and indeed my save files were fine. Sorry for the confusion. At least if someone else comes under a similar misconception they'll find this thread I suppose.
     
    JuliusM likes this.
  4. beechan

    beechan

    Joined:
    Feb 4, 2020
    Posts:
    2
    How were you able to solve your original problem? Currently facing the same thing and users are not happy :(
     
  5. Sudden62

    Sudden62

    Joined:
    May 3, 2017
    Posts:
    11
    I think originally I uninstalled my app before updating to the new version. This deletes everything located at the PersistentDataPath. If I understand correctly, you updated your app and users lost their data? It won't be because of Version # or the Bundle Version #. I can think of 2 possibilities:

    Assuming you're saving data to PersistantDataPath...
    1) You changed the Package Name, which determines where PersistantDataPath points to.
    2) You updated how data is saved and loaded without accounting for the old file format.

    I hope that might have helped some!