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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

*Urgent* Google play App update = No save

Discussion in 'Scripting' started by Loff, Oct 29, 2017.

  1. Loff

    Loff

    Joined:
    Dec 3, 2012
    Posts:
    81
    Hey,

    I just released my game and some few players reports that their saves gets deleted whenever they update the game from google play.
    My beta testers didn't have this issue. Maybe 1 of them but we thought it was other reasons.

    It's nothing worse than losing progression for no reason so I want to fix this asap if possible.

    I use this for save (just example)
    Code (CSharp):
    1.  BinaryFormatter bf = new BinaryFormatter();
    2.         FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat");
    3.         PlayerData data = new PlayerData();
    4.  
    and load:
    Code (CSharp):
    1. if (File.Exists(Application.persistentDataPath + "/playerInfo.dat"))
    2.         {
    3.             BinaryFormatter bf = new BinaryFormatter();
    4.             FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", FileMode.Open);
    5.             PlayerData data = (PlayerData)bf.Deserialize(file);
    6.             file.Close();
    7.  
    I read that other people have this issue as well. it could be pathing issues (Application.persistentDataPath), android update issues etc but I haven't found a solution yet.

    Any idea what I could do?
    Edit:
    (Player settings)
    Install location = Prefer External
    Write Permission = Internal

    I use S6 and have no issues.
    My friend has S7 and his saves gets deleted.
     
    Last edited: Oct 29, 2017
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    I once had an issue where the persistantDataPath was changing after the first load. So we could start it up, play for the first play through and everything saved correctly. But then on the second playthrough, the game started fresh.

    Used https://www.assetstore.unity3d.com/en/#!/content/12047 log viewer and had a debug that printed out what persistantDataPath was and the first time it pointed to one location I think on the internal card, but then because permission was granted, the second time, persistantdataPath pointed to the external card. This was on an older Android OS and using an older version of Unity since it was an update to the app, but similar thing could be happening to you, so I would try that and see what persistantdatapath points to.

    Now, that being said, just updating from google play shouldn't change things, so again, use something like log viewer and test on your friends device to maybe see what is happening.

    Since we were just saving json strings, we just ended up switching to playerprefs to save the data and that was enough to fix it for us.

    Other than that, not sure what would change for you.
     
  3. Loff

    Loff

    Joined:
    Dec 3, 2012
    Posts:
    81
    Thanks for your responds and sharing your experience :)
    Did a small update yesterday and his save wasn't deleted. I have a feeling it could be connected with updating from Alpha -> Beta -> Release. He responded saying his save was deleted after buying something from my store which doesn't have any connection to the saves what so ever. It could have been a update as well thought. Troubleshooting others devices without seeing it yourself can be a pain.
    will do some more digging however.
    Thanks again!
     
  4. georgikrastev

    georgikrastev

    Joined:
    Aug 26, 2015
    Posts:
    13
    Same thing happening to me. Did you ever solve this?
     
  5. Loff

    Loff

    Joined:
    Dec 3, 2012
    Posts:
    81
    Unfortunately I ended up going back to PlayerPrefs. I changed my scripts so I didn't have that much to save. Would be nice to know a solution for other projects.
    Think I read that some people use PlayerPrefs to save the location of the files. Than load/save at that location. However I did not want to test that so I have no clue if it works.