Search Unity

Public List not appearing in inspector

Discussion in 'Scripting' started by ToastHatter, Mar 3, 2018.

  1. ToastHatter

    ToastHatter

    Joined:
    Nov 11, 2016
    Posts:
    53
    For some reason the list I am attempting to use Is not appearing in the inspector, I have restarted unity several times and that doesn't seem to work.

    Have i done something wrong in the initialisation of the list/array?
    upload_2018-3-3_16-41-46.png

    upload_2018-3-3_16-41-35.png
     

    Attached Files:

  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Unity's serialization system doesn't like that. You'll need another type to wrap the array and create a list of that wrapper type instead.
     
    AlanMattano likes this.
  3. ToastHatter

    ToastHatter

    Joined:
    Nov 11, 2016
    Posts:
    53
    I am unsure as how to do this, can you link me to something or provide an example please?
     
  4. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Either a class or a struct:

    Code (CSharp):
    1. [System.Serializable]
    2. public class GOArray
    3. {
    4.     [SerializeField]
    5.     private GameObject[] _gameObjects;
    6.  
    7.     // optionally some other fields
    8. }
    Then, just use it like
    Code (CSharp):
    1. [SerializeField]
    2. private GOArray[] _array;
    3.  
    4. [SerializeField]
    5. private List<GOArray> _list;
     
  5. ToastHatter

    ToastHatter

    Joined:
    Nov 11, 2016
    Posts:
    53
    Ah ok, Thank you :)