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:

  1. Get old save file and data.
  2. Add new variables to data.
  3. Save new save file that includes new variables.

Thanks in advance for any guidance! :slight_smile:

I think this is the article in MSDN you should read: