Undocumented EditorGUI.Popup Feature

Hi Unity,

I was playing around in PropertyDrawers today and found an undocumented feature of EditorGUI.Popup. When you format your displayedOptions array elements with “/” characters in the strings the popup will create sub-menus collecting options that shared the same roots.

So for instance the code below will generate the popup menus in the linked image.

int selectedIndex = EditorGUI.Popup(
      position,
      label.text,
      0, 
      new string[4] { "Split1/Value1", "Split1/Value2", "Split2/Value1", "Split2/Value2" });

I know that this is known to a few others but I just happened to stumble across this feature as I was unaware it was even possible. I would have loved to have known about it on an earlier project this year. I’d like to put in a request to have this feature added to the documentation of EditorGUI.Popup so that others can benefit from it.

Sarah

Hi Sarah,

Thanks for pointing that out. I’ve made a note to have this added to the docs. By the way this also works for the layers and tags menu items!

2370619--161032--penfold.gif

1 Like

Thanks for getting back so quickly and for that excellent animation.