Search Unity

Performance optimization for custom class in ScriptableObject

Discussion in 'Scripting' started by gareth_untether, Sep 20, 2020.

  1. gareth_untether

    gareth_untether

    Joined:
    Jan 5, 2018
    Posts:
    69
    Having read about Custom Serialization in the docs I am left wondering if I should be using custom classes inside of ScriptableObjects.

    For example I have an SO called ItemState that holds a list of of another SO:

    Code (CSharp):
    1. [CreateAssetMenu(fileName = "State_Item_StateName", menuName = "ScriptableObject/States/ItemState")]
    2. public class ItemState : ScriptableObject
    3. {
    4.     [SerializeField] public List<EventBase> Events = new List<EventBase>();
    5. }
    So has its own classes, for example:

    Code (CSharp):
    1. [SerializeField] public ItemState NextState = null;
    2.     [SerializeField] public SpreadsheetData[] ReactionsEventMessages;
    3.  
    4.     [HideInInspector] public int ItemID { get; set; }                    
    5.  
    6.     [System.NonSerialized] public ItemStateManager ItemStateManager;
    For the classes that don't need to be serialized I have added the NonSerialized attribute. However, I am wondering if my approach is generally wrong.

    Would someone be able to tell me if I am using SOs incorrectly? I love the modular approach, but am concerned that I'll be taking a performance hit or is it just increased build times?