How do I add new variables to existing Playerdata serialized file?
I use data serialization as described in THIS live session on scripting. It's working great.
My problem: I have an update to my game that has 2 additional variables that need to be part of that save data file. How do I make sure that those 2 new variables are inserted to existing data files that people already have on their devices without messing up saved data in that file that is already there? When a person starts the game (on android or iOS), one of the first things the game does is load that save file. If I update my code to include those 2 new variables, when the game tries to load the save file it gets messed up because the old save file is still missing those 2 variables.
Not sure if that is clear as I've described it or not... Hope it is. I'm assuming there must be a way to have a script run just when the app/game is updated to the new version. Is that correct, and if so, how do I get that in my Unity project? If I could do that, the script would be easy enough:
Get old save file and data.
Add new variables to data.
Save new save file that includes new variables.
Thanks in advance for any guidance! :)
Answer by hexagonius · Feb 11, 2017 at 09:08 AM
I think this is the article in MSDN you should read:
https://msdn.microsoft.com/en-us/library/ms229752(v=vs.110).aspx
Your answer
Follow this Question
Related Questions
Keep data created at runtime in ScriptableObjects? 1 Answer
How to save class data(variables) into an asset file in editor ? 1 Answer
How to Serialize or Save a List of GameObjects 1 Answer
How the heck do I save this info for my characters? [Serialization Usage Question] 1 Answer
OnBeforeSerialize is called twice before OnAfterDeserialize 2 Answers