- Home /
Question by
KloverGames · Jan 21, 2021 at 09:54 AM ·
updategoogle playsave datagoogle play games
how to keep player data after update?
I have the generic code for a save file, but in internal testing on Google Play, the app's save data is overwritten and god knows what's happening with production. So I was wondering how to create a save file that keeps the data even after an update.
public static void SaveStats(UIManager manager)
{
BinaryFormatter formatter = new BinaryFormatter();
string path = Application.persistentDataPath + "/usc.GameData";
FileStream stream = new FileStream(path, FileMode.Create);
PlayerData data = new PlayerData(manager);
formatter.Serialize(stream, data);
stream.Close();
}
public static PlayerData LoadStats()
{
string path = Application.persistentDataPath + "/usc.GameData";
if(File.Exists(path))
{
Debug.Log("File found" + path);
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(path, FileMode.Open);
PlayerData data = formatter.Deserialize(stream) as PlayerData;
stream.Close();
return data;
}
else
{
Debug.Log("File not found" + path);
return null;
}
}
Comment
You could append the new data to the file, but you would have to change how you read it. For example, your file (after being formatted to ascii again) may look like:
---SAVE DATA 01/01/2020---
playerdata: ....
---SAVE DATA 03/01/2020---
playerdata: ....
Then, you'll have to read the latest save data, but you could retrieve older saves, if you wished. @greenklover
Your answer
Follow this Question
Related Questions
Will appending a save file keep your save after an update? 0 Answers
Google play save data 1 Answer
Google play save doesn't work 1 Answer