Search Unity

Question drop down select for an item of an array in inspector

Discussion in 'Scripting' started by Javed_Wilde, Mar 16, 2023.

  1. Javed_Wilde

    Javed_Wilde

    Joined:
    Jan 25, 2018
    Posts:
    3
    i have an array which im populating in the inspector,
    and a script is picking an element from this using a string identifier provided in the inspector.

    what i want is, a drop down that populates itself with the items in the array, as mentioned im using strings right now but id like a drop down or just the ability to pick an element from the array.

    can use enums but i dont wanna update the enum everytime i add an element in the array.
    any help?
     
  2. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
  3. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    The previous answer assumes that you write your own inspector. You can also write your own custom drawer, which is easier for your case, however there is a lot to unpack whichever path you choose. Writing a custom drawer is relatively easy once you find a decent template. You can check out this solution of mine I shared here not so long ago. It is more broad, but features a custom popup drawer. (You can also download the source in post #12)