Loading a serialized file after changing the adding a new var to it


I’m loading all the data of my game using

            SaveVariables.current = (SaveVariables)bf.Deserialize(file);

But I have to add a new variable to SaveVariables, like that :

using UnityEngine;
using System.Collections;

public class SaveVariables
    public static SaveVariables current;

    public int c = 500;

    public bool[] m = new bool[4];
    public bool[] md = new bool[4];

    public bool[] p = new bool[5];
    public bool[] pd = new bool[5];

    public int roundsPlayed = 0;
    public int gamesPlayed = 0;
    public int bulletsShot = 0;
    public int grenadesShot = 0;
    public int lazersShot = 0;
    public int bouncyShot = 0;
    public int playersDead = 0;
    public int powerupsDestroyed = 0;

    public bool sound = false;
    public int ad = 0;
    public string adTime = "";
    public bool rated = false;
    public string newVar = ""; // NEW VARIABLE

After adding the new var, I’m getting an error because an error because this newVar don’t exists in the save file
How can I fix that ?

Check out the OptionalFieldAttribute. it’s basically what you need. it lets you change the class, adding in new fields marked with this attribute so they will be defaulted on deserialization of data that do not contain them, not throwing errors.

i doubt its possible. just output your files as plan text until your ready to publish