ScriptableObject

Overview

This library supports serializing and deserializing ScriptableObject fields.

These are serialized the same as a Complex Type.

Similarly, they must also be marked with the SerializableAttribute.

Serialization

ScriptableObject fields are serialized as a TOML table, by default.

To override the default behavior, mark the field with the TomlInlineAttribute or TomlExpandAttribute.

Use the NonSerializedAttribute to prevent a field from being serialized.

Deserialization

ScriptableObject fields are deserialized from TOML as a TOML table.

You must use the DeserializeInto method to deserialize into a ScriptableObject. This is because the serializer cannot create a new instance of the ScriptableObject type.

You can manually create instances via ScriptableObject.CreateInstance and pass them to DeserializeInto.

Example

[Serializable]
public class PlayerCharacter : ScriptableObject
{
    private string _name;
    private int _level;
    private int _experience;
    private int _gold;
    private int _health;
    private int _mana;
}

Can be serialized and deserialized as the following TOML document:

name = "Player"
level = 2
experience = 250
gold = 85
health = 100
mana = 50