- Home /
The question is answered, right answer was accepted
EditorGUILayout.Popup() ignores repetitive Strings in the Array
So i have been making a Popup in OnInspectorGUI() , and wanted to display a dynamic popup, and when i pass a repetitive string for the array, it only displays 1 of them, here is an example:
int index = EditorGUILayout.Popup("My Popup",myScript.index,new string[] {"Content","Content"});
Here i have a String Array, that has the length of 2, and has "Content" and "Content" in it, and the Popup only displays one "Content".
Is there any way to make/force it to display both? Thanks.
Answer by Bunny83 · Mar 27, 2018 at 12:00 PM
No you can't because Popup uses EditorUtility.DisplayCustomMenu. The menu items represent path strings which could include submenus. They need to be unique. It doesn't make much sense to display two or more items with the same content anways.
$$anonymous$$y purpose for doing this is to allow the user to select a specific item in the inspector, let me explain:
Here is a list "States", which is a list of a class "State", and the class contains:
-A string "Name".
-Anything else..
And here is an integer variable "Index", which selects from the "States" list, and has a String Array "StateNames" that sets its Length
to States.Count
, and sets each of them to State.name, like:
StateNames[a] = States[a].name;
, so if they have an identical name like "Untitled", it will display 1 option/content only.
But thanks for your answer.
EDIT: Sadly, this is the only way to solve the Issue, which isn't exactly what i am looking for:
int index = EditorGUILayout.Popup("$$anonymous$$y Popup",myScript.index,new string[] {"0 - Content","1 - Content"});
Which is adding an Index number for it.
But again, why would you let the user choose between two items that he is unable to distinguish anyways? The question here would be why are there two "states" with the same name in the first place? Note you said if they have a "similar" name. However similar is not the same as "identical". As an easy fix you can simply add the index to the string (at the front or at the end.) Something like
StateNames[a] = States[a].name + "(" + a + ")";
So even when the "name" is an empty string each string will be different.
Yeah i guess both of our solutions would work, if the List has the Count of 2, and both of them have "Untitled" in their name, the popup only shows 1 "Untitled" option, but anyways, thanks, i used that method before even posting the question and thinking if there was another way of doing it without adding numbers into it.
EDIT: So i guess there isn't any other way to do that, and since our solutions are the same, then there isn't any other way to do it, so i will accept the answer.