plusAdding New Save Data

Suppose you need to save, for example, the "player’s number of wins" (int WinsCount).

  1. Add a field to PlayerProgress

    This is the main data structure that gets serialized.

public class PlayerProgress
{
    // ...
    public int WinsCount = 0; // new field
    // ...
}
  1. For dictionaries: use DictionarySerializeContainer<TKey, TValue> If you need to save a Dictionary, Unity doesn’t serialize it directly, so a special container is used. For example, see how the WalletsData type is implemented in the project.

  2. In DefaultPlayerProgress.cs, add a default field This file sets the default values for new progress if no save exists.

public class DefaultPlayerProgress
{
    // ...
    public int WinsCount; // default value
    // ...
  1. Open the DefaultPlayerProgress config and set the desired default value in the inspector, for example, WinsCount = 3.

  2. In LoadProgressState.NewProgress(), you need to initialize PlayerProgress.

  1. Create a class for reading/writing this field.

Create a MonoBehaviour or a regular class that implements both interfaces:

7. To make Zenject aware of the PlayerWinsTracker and ensure it’s properly injected and registered in the save system, add a binding method in your GameplayInstaller:

How to reset progress

Last updated