Advanced Use

Bypassing the Wizard

The Wizard is here to help non-programmers get a hang of the suite. You are not forced to use it: once you’ve got a grasp on how everything works, feel free to simply create your own classes.

Once the Wizard has created the files, you are free to edit them.

Using more complex types

  • « Using » clauses: the wizard only adds the UnityEngine namespace to your scriptable object type. You are free to add any other namespace that you might require to compose your object:
    • System.Collections.Generic;
    • UnityEngine.UI
    • etc.
  • Custom methods: define any method you would like in the file, without any restriction
  • Classes / Structs: as long as your field type is tagged with the [System.Serializable] attribute, you can add a field of this type inside your object. For instance, the following type is completely valid as a field for your object:
    public class UnlockCondition
        public UnlockConditionType ConditionType;
        public int ConditionParameter1;
        public int ConditionParameter2; 

Load on demand / Managing your memory

  • By default, Unity cascade loads any serialized object.
    Let’s take an example: I’m designing a card game; each card is a scriptable object with the following type:

    public class Card: ScriptableObjectExtended
    	public int Power;
    	public int Toughness;
    	public string CardText;
    	public Texture2D CardImage;
  • To avoid this issue, Scriptable Object Suite allows you to have fields load only when you want to. Here’s how it works:
    • Put all of your card textures in a folder inside a Resource folder
    • Use a [LoadOnDemand] attribute trick to specify that a field will not be loaded automatically:
      public Texture2D CardImage;
      private LoadOnDemandInfo m_CardImageLoDInfo;
      • The CardImage field is tagged as NonSerialized, to avoid the cascade loading
      • Add a LoadOnDemandInfo field that is serialized and will hold info as to where the asset is located. The LoadOnDemand string parameter « CardImage » links this path to the actual CardImage Texture2D field
    • A slight change appears on the edition window: a « Load on demand » tag appears on the CardImage field, telling that this field will not be loaded by default
  • Any type of asset can be loaded on demand, as long as its located inside a resource folder

Triggering a load / unload action

  • Once you have a reference on a ScriptableObjectExtended object, you can call the Load method to load Load on Demand fields:
    List<Card> m_CardDatabase;
    Card myCard = m_CardDatabase[3];
  • The Load method takes two optional parameters:
    public void Load(string fieldName = null, bool async = false);
    • The fieldName parameter allows you to load only a single field of your object, if it contains multiple Load on Demand fields. Set to null to load all fields.
    • The async parameter allows you to asynchronously load your object. By default, the loading is synchronous
  • Similarly, an Unload method exists to unload Load on Demand fields:
    public void Unload(string fieldName = null);
    • The fieldName parameter allows you to unload only a single field of your object, if it contains multiple Load on Demand fields. Set to null to unload all fields
    • Unload actions are always synchronous


Next: Customizing the Editor Window