Choosing what is saved

Only certain fields are saved by default (see Supported Types). To save other fields or properties, you can use attributes or ES3Types.

The [ES3Serializable] attribute is used to tell Easy Save to serialize a field or property which is not automatically serialised.

You can use the [ES3NonSerializable] to prevent a field or property from being serialized.

In some cases it’s not possible to add attributes, so it’s necessary to create an ES3Type.

An ES3Type script tells Easy Save what fields and properties of a type to save and how to save them. This can be created automatically, and modified if necessary.

Once the script is created, Easy Save will automatically find it and use it to serialize and de-serialize your type. You do not need to create an instance of the ES3Type.

EasySave3TypesWindowCreating an ES3Type

An ES3Type can be created by going to the Window > Easy Save 3, and selecting the Types tab.

From here you can select your Type from the list and choose the fields and properties you wish to save.

Saving a field or property which is not explicitly serializable can have undesired effects, so you should ensure it’s safe to serialize before selecting it.

Manually modifying an ES3Type

In some cases you will need to modify the ES3Type. For example:

  • When the type does not have a parameterless constructor.
  • When you need to call a method to access the variable you’re saving/loading.

You can do this by modifying the Write, Read and ReadInto methods of the ES3Type script generated in the Types pane. The ES3Type script can be found in /Assets/Easy Save 3/Types/.

Note that once you manually modify the ES3Type file, any changes made in the Types panel will overwrite your manual modifications.

Modifying the Write method

You can change what properties are written by modifying or adding reader.WriteProperty calls in the Write method.

Note that UnityEngine.Object types such as MonoBehaviours and ScriptableObjects will be written by reference.

Modifying the Read Method

The Read method uses the reader.Properties enumerator to get the name of each property, and a switch statement with reader.Read calls to read the value of that property.

By changing or adding cases in the switch statement you can change which properties are serialized.

If the class you’re saving does not have a parameterless constructor, you will also need to modify the ReadObject<T>(ES3Reader reader) method to create an instance with appropriate default values. For example: