Search Unity

Why need to wrap a list for serializing it?

Discussion in 'Scripting' started by X3doll, Apr 20, 2020.

  1. X3doll

    X3doll

    Joined:
    Apr 15, 2020
    Posts:
    34
    This should be an odd question but i need a explanation. Why i need to wrap my List of gameobject for serializing it?

    Why i can't access the public field list into the inspector in this way?
    Code (CSharp):
    1. [SerializeField] public List<PickableTestObject> pickablesInRange;
    It's so smart, intuitive and clean serialization, but if works with variables, why should not works with list?

    I search on EVERY post and everyone turn out with a lazy solution like this:

    Code (CSharp):
    1.  [System.Serializable]
    2. public class UglyWrapper
    3. {
    4.       public List<PickableTestObject> pickablesInRange;
    5. }
    It's so bad and ugly to create a class only for serializing a list.
    I would know if I have wrong or not understood something ( i already know the "Because you can serialize MonoBehaviour class" concept)
     
    Last edited: Apr 20, 2020