Search Unity

How to make a editable list in editor that doesn't need a size parameter

Discussion in 'Editor & General Support' started by craig4android, May 14, 2019.

  1. craig4android

    craig4android

    Joined:
    May 8, 2019
    Posts:
    124
    like when I derive a MonoBehaviour

    and add a public array to it like:

    Code (CSharp):
    1. public float[] values;
    I can add those values but I also have to set the size, I wonder how I can make a list for the editor, which doesn't need a size parameter.
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    You can't. A list needs a size.
     
  3. zkajo

    zkajo

    Joined:
    Jul 28, 2016
    Posts:
    9
    Code (CSharp):
    1. List<string> listOfStrings = new List<string>();
    You use listOfStrings.add("yourStringToAdd") when you want to add an element, and there is a bunch of remove functions also. Make sure the list is instantiated with "new".
     
  4. craig4android

    craig4android

    Joined:
    May 8, 2019
    Posts:
    124
    but other UI components can, you can just add a elments by pressing the plus sign.
     

    Attached Files:

  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296