Search Unity

Save file gets deleted when updating on Android?

Discussion in 'Android' started by Catobyte, Feb 24, 2016.

  1. Catobyte

    Catobyte

    Joined:
    Sep 27, 2015
    Posts:
    4
    I have been searching for an answer to this but can't find one. I have a unity game that is in alpha in the google play store, but updating to newer versions of the game wipes the save file. I am saving to a text file for now using Application.persistentDataPath + "SaveData.txt". I am expecting to change this later to binary. The game does not require permissions to write to external SD cards. It is set to "Prefer External" for install location.

    I have avoided user PlayerPrefs as I have heard bad things about it (can easily be opened and edited, and also sounds as if it is often wiped upon updating the app). Does anyone know how to resolve this? I am unable to release my game due to this issue.
     
  2. Deleted User

    Deleted User

    Guest

    I have this issue too. I dont think its got anything to do with the save file being wiped instead its the problem with Unity persistentDataPath accessing the wrong directory. I still havent solved it yet.
     
  3. Catobyte

    Catobyte

    Joined:
    Sep 27, 2015
    Posts:
    4
    I think you might be right about Unity getting the wrong directory as persistentDataPath. I tested Application.persistentDataPath on an older android version (Gingerbread), and debugging revealed it to be pointing to "/data/data/com.mycompany.mygame/files/". I ran the same test on a newer android version (Marshmallow on Nexus 5) and Application.persistentDataPath was reported as being "/data/user/0/com.mycompany.mygame/files".

    I have now hardcoded the older directory as my path for saving ("/data/data/com.mycompany.mygame/files/"), and it seems that save files are no longer deleted between updates from the Google Play store on the newer device (Marshmallow) (though I have only tested once on Nexus 5).

    For the player settings, I have Write Access : Internal Only, with Install Location : Prefer External.

    It would be good if someone could clarify that this is a "safe" solution to the problem.
     
    pango and Deleted User like this.
  4. Deleted User

    Deleted User

    Guest

    Wow thanks man! Your amazing! I will try it out when I get the chance.
     
  5. JennyHide

    JennyHide

    Joined:
    Sep 30, 2014
    Posts:
    47
    Did this work/did you find another solution to this? I'm having the same problem - I also have a game that's in alpha in GooglePlay, but updating to newer versions of the game sometimes (but not always) wipes the save file.

    My understanding of Application.persistentDataPath was that it could be different for different operating system versions since the path is only persistent per device/operating system (it's not meant to be the same path for all devices over different operating systems). So updating your phone from Gingerbread to Marshmallow could change the persistent path (which is bad), but it shouldn't change when you update your app.. is that wrong?
     
  6. VictorQianUnity

    VictorQianUnity

    Joined:
    Nov 13, 2015
    Posts:
    30
    Sorry to bump this old post, but i saw many games made by Unity have this problem on the Google Play, all you need to do is to check the game review, you will see a lots of players report save reset and its really bad for the business.

    I personally received a lots of e-mail complain about this, all those players are royal and paid players that had played my game for weeks even month, and all I can do is say sorry and give them some redeem code.

    Does Unity dev team realize this problem? is there any better solutions? I can understand if the persistentDataPath change upon OS update, but why it will change upon App update?

    My player settings on Android are "Write Permission - External(SDCard)" but when I use a phone with SD card installed on it, persistentDataPath returns the internal path, why? and how does the persistentDataPath decide when to use Internal or External? It will choose External by default when the Write Permission is External? but it does not behave this way on my device.
     
    Last edited: Dec 31, 2016
    mimiCryMuffin likes this.
  7. lloydg

    lloydg

    Joined:
    Mar 23, 2015
    Posts:
    36
    I am also having this issue! Please fix this Unity.
     
    mimiCryMuffin likes this.
  8. lloydg

    lloydg

    Joined:
    Mar 23, 2015
    Posts:
    36
    Looks like save files from earlier unity version could be in a few different paths.

    My research so far shows me these locations:
    Code (CSharp):
    1. /data/data/com.mycompany.mygame/files
    2. /data/user/0/com.mycompany.mygame/files
    3. /data/user/11/com.mycompany.mygame/files
    4. /mnt/expand/<uuid>/user/0/com.mycompany.mygame/files
     
  9. Rod-Green

    Rod-Green

    Joined:
    Apr 19, 2010
    Posts:
    51
    This is still an issue even on the latest version of Unity.

    It's not a paths issue as people have stated or an Android version issue.

    I created a reporting system that detected when the folder has been wiped and there are a very small number of path changes but almost all of the reports have:

    Pre-update path:
    "/storage/emulated/0/Android/data/com.lonelyfew.blendoku2/files"

    Post-update path:
    "/storage/emulated/0/Android/data/com.lonelyfew.blendoku2/files"

    The only difference is the folder is completely wiped - interestingly the PlayerPrefs are never wiped. So others might not even know this is an issue if they don't attempt to write to the folder.
     
    mimiCryMuffin likes this.
  10. yhiroki

    yhiroki

    Joined:
    Jul 1, 2015
    Posts:
    2
    Hi.

    I have same issue about my app. What is the best solution of this problem? Already many android users are playing my app. So I want to solve this problem without affecting current players' save data.
     
  11. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    345
    I upgraded to unity 5.6 but this issue is still present.

    Users are updating the app from app store and after the update all save files are gone. Persistent path is changing when app is updated?
     
  12. Nan77777

    Nan77777

    Joined:
    May 27, 2016
    Posts:
    1
    Currently Also facing the issue and my game is in beta in the Playstore. Bumping this post in hopes for more help, Right now my data is getting wiped every time i save and like others pointed out using persistentdatapath even if it works may not be the right solution and i hope someone can provide one or start a discussion on the options available.

    An Option available for me but am not sure if it works is that i have implemented Google Play Games Services. If i'm using cloud save from google play games services will it solve this issue? However the problem with this will be if the player doesn't want to use his/her google account or doesn't have one.
     
  13. Peacewise

    Peacewise

    Joined:
    Feb 27, 2014
    Posts:
    52
    I have been trying to figure this out as well, as we've had Android players bumping into this for a couple years, *every time* we update our game.

    Specifically:
    1. Player updates game on Android
    2. Player loads game
    3. Very small chance that the player finds their save files have been wiped
    We have hundreds of thousands of DAU, and reports of data loss on update are less than 1 in 1000, so the likelihood of it happening to any one player is low, but it all adds up across a large player base and over frequent updates.

    Maybe a smart Unity Dev like @Mantas-Puida @MartinTilo or @Ignas83 have some insight into the issue in this thread?

    EDIT: We experience this with multiple games at our company with totally different save/load code. The consistent factors here are Unity, Android, App Update, and data in Persistent Data Path.
     
    Last edited: Sep 18, 2018
  14. pertz

    pertz

    Joined:
    Jan 8, 2015
    Posts:
    106
    I am on a similar situation, people complaining on every update that the data is lost since I migrated to Unity (when my game was on a previous engine I didnt get this complains). Less than 1% of the players suffer this data loss. Right now Im migrating my game to stop using the EXTERNAL permission and see if it fixes the problem.
     
  15. tomtominc

    tomtominc

    Joined:
    Nov 7, 2013
    Posts:
    22
    Has anyone been able to solve this?
     
  16. s4relok

    s4relok

    Joined:
    May 1, 2013
    Posts:
    3
    Any news about this issue? It's still happening.
     
    awsapps likes this.
  17. Diviatrix

    Diviatrix

    Joined:
    Mar 22, 2012
    Posts:
    2
    And still happening to me
     
    awsapps likes this.
  18. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    +
     
    awsapps likes this.
  19. bart_the_13th

    bart_the_13th

    Joined:
    Jan 16, 2012
    Posts:
    498
    This happens to me too... It seems to only happen when I enabled IAP in my games, I cant add IAP to my game without risking player lost their progress.
     
  20. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,968
    Can someone explain in detail about the issue?
    Do you mean when using "Prefer External" its getting wiped out after update or when using Internal?

    We didn't face this kind of issue earlier however, we always use cloud save though so need to give a test once if the persistentDataPath changes as we change the internal or external setting.
     
  21. mikhail111777

    mikhail111777

    Joined:
    Feb 8, 2013
    Posts:
    84
    I've just spent 5 hours debugging this crap. The problem is that Unity 5.xx has persistentDataPath pointing to "/data/data/com.xxx.yyy/files", but Unity 2018.3 points to "/storage/emulated/0/Android/data/com.xxx.yyy/files". On my device these are different paths.

    RIght now I've found a solution to replace persistentDataPath with this code:
    Code (CSharp):
    1.             using (var unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
    2.             using (var activity = unityClass.GetStatic<AndroidJavaObject>("currentActivity"))
    3.             {
    4.                 persistentDataPath = activity.Call<AndroidJavaObject>("getFilesDir").Call<string>("getAbsolutePath");
    5.             }
    6.  
     
    Last edited: Mar 25, 2019
  22. ZenithGames

    ZenithGames

    Joined:
    Mar 26, 2017
    Posts:
    15
    Hey guys. Have you encountered lost PlayerPrefs also?
    It's really hard to find, if you make single-player, local games, but in my multipleyer game (with a remote server) I found out that 1% of my users is affected with loosing their prefs - they're registering multiple times, because their credentials are getting wiped from PlayerPrefs.
     
  23. Raikish

    Raikish

    Joined:
    Mar 19, 2019
    Posts:
    5
    Hey, what about to hardcode the path for all platforms and forgot about Application.persistentDataPath? for android would be something like "/storage/emulated/0/Android/data/com.myawesomecompany.myawesomeapp/files";
     
  24. alex1st1

    alex1st1

    Joined:
    Jan 26, 2019
    Posts:
    275
  25. alex1st1

    alex1st1

    Joined:
    Jan 26, 2019
    Posts:
    275
    And from security point, do you think that file is more secure than pref?
    If you need security - cipher both
     
  26. beechan

    beechan

    Joined:
    Feb 4, 2020
    Posts:
    2
    This is still happening for me. Anyone found a solution for this?
     
    mimiCryMuffin likes this.
  27. unity_gorSHOZ0kQgFPA

    unity_gorSHOZ0kQgFPA

    Joined:
    Jun 17, 2020
    Posts:
    1
    You must use remote database like Firebase for instance to solve this
     
  28. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,968
    Or
    Use Cloud Saving services(iCloud/Saved Games) which are free on both the platforms.