• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Mar 30, 2018 at 02:36 PM by $$anonymous$$ for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by $$anonymous$$ · Mar 27, 2018 at 11:37 AM · enumeditorguilayoutpopuppop-upenumpopup

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image $$anonymous$$ · Mar 27, 2018 at 12:09 PM 0
Share

$$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.

avatar image Bunny83 $$anonymous$$ · Mar 27, 2018 at 12:18 PM 0
Share

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.

avatar image $$anonymous$$ Bunny83 · Mar 27, 2018 at 12:22 PM 0
Share

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.

Show more comments

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

76 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Type cast to a enum? 1 Answer

EnumPopup an enum from another class 1 Answer

What is the efficient way of showing variables depend on enum in custom inspector? 2 Answers

EditorGUILayout.EnumPopup giving me errors 1 Answer

Customizing the item rendering in a EditorGUILayout.Popup 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges