I am using MessagePack with Unity to save data of my game.
This is the struct where all the data is stored:
[MessagePackObject]
public struct Data {
[Key(0)]
public Level[] levels;
[Key(1)]
public float menuContentScroll;
[Key(2)]
public bool musicOn;
[Key(3)]
public int worldHighScore;
[Key(4)]
public bool tiltControlsEnabled;
[Key(5)]
public bool autoRestartEnabled;
}
Here is the level struct:
[MessagePackObject]
public struct Level {
[Key(0)]
public int length;
[Key(1)]
public bool completed;
[Key(2)]
public int highScore;
[Key(3)]
public int attempts;
}
Everything have been working good unitil now when I decided to add two booleans to the data struct, tiltControlsEnabled and autoRestartEnabled. Now these two do not get serialized and stored to disk and are therefore reset every time you start the game, unlike for example musicOn which is being stored.
I experimented by logging to the console the json version of the serialized byte[] and there I saw clearly that the two members are not there. When I instead tried using Unity's JsonUtility everything worked fine.
I solutioned. I had to regenerate MessagePackGenerated.cs as the new values were not there.