Search code examples
unity-game-engineunity3d-guiunity3d-editor

EditorGUILayout.Popup option is not changing


using this simple code I'm showing a dropdown

 int selected = 0;
            ///*
            string[] options = new string[]
            {
                "Start With", "End With", "Contains", 
            };

            //criteria = EditorGUILayout.Popup("Search Criteria", 2, options);
            //*/
            criteria = EditorGUILayout.Popup("Awesome Drop down:",  selected, options, EditorStyles.popup);

it showing dropdown with option perfectly but the problem is option is not changing when I try to select another option? what is missing?


Solution

  • don't use "selected" AND "criteria". you must use the same ONE variable:

            int selected = 0;
            ///*
            string[] options = new string[]
            {
                "Start With", "End With", "Contains", 
            };
    
            //selected = EditorGUILayout.Popup("Search Criteria", 2, options);
            //*/
            selected = EditorGUILayout.Popup("Awesome Drop down:",  selected, options, EditorStyles.popup);
    

    because this is the way your choice is saved