Save game patterns - how do you do it?

I’m looking for thoughts/feedback on persistance/save game friendly design pattern. I like how the author of this article approached it: __Blogs recent news | Game Developer

I’m thinking of moving all of my state variables for every component that needs to be saved to its own state class ClassName_State then referencing that from the Monobehaviour

So for example going from

public class Example : MonoBehaviour {
     float health = 1f;
}

To something like this:

public class Example : MonoBehaviour {
    Example_State state = new Example_State();

    public void Load(Example_State state) {
      this.state = state;
      transform.position = state.position;
    }

}

[Serializable]
public class Example_State {
    Vector3 position;
    float health = 1f;
}

Please share your thoughts or approaches you’ve tried for your save game logic/architecture.

Hey td-lamda,

I have used the above method a number of times and like it. You just have to be careful as your state object might not fit every case you want to save so you might end up having adding a whole bunch of fields that dont fit or create a number of classes.

In my game im going to explore creating a SaveManager that just serializes a key-value pair dictionary or similar for each property thats being saved and have each object ask it if it has anything worth loading. I like the idea of saving blobs of data that could be anything and avoiding the complication of maintaining a number of state classes.