Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

EditorGUILayout.Popup - Problem

Discussion in 'Immediate Mode GUI (IMGUI)' started by delibowlen, Mar 4, 2015.

  1. delibowlen

    delibowlen

    Joined:
    Jan 16, 2013
    Posts:
    57
    Hi,
    I´m making an editor extension for a script of my project and there I have a Popup where you can choose an object:

    Code (CSharp):
    1. index2 = EditorGUILayout.Popup("Channel", index2, channelCount);    


    "Index2" is the Index-Value which contains the position inside the popup, "channelCount" is a string[] which contains the object names. The channelCount value is filled dynamically by searching the objects.

    And now here is my problem: When I select the last object inside the popup and this object will be deleted, the "channelCount" value won´t contain it any more, but in the popup it´s still selected at the "index2" position. This generates an error like "Array index is out of range".

    Now here´s my question: How can I get the "popup/index2" to select automatically the last entry depending on the count of the "channelCount" value. It would be enough when I could select the first entry via code but I can´t get it right.

    Greetz and thx