Unity Dropdown shows the first time around, duplicated text

Viewed 517

I am having this issue where I have a dropdown that should say finances, inventory, and stats. Which when you click on it will cause other panels of UI to appear. Now for some reason, the options it says it has is all Money:(which is the first item name of the first option). Why is that? I've attached images below that show what I mean. Sorry about the links i dont have high enough rep yet

Duplicated Text of Money

Another instance of ^

My Tabs

Dropdown Setup

2 Answers

Let's take a closer look at your third and fourth pictures and compare them to the default Dropdown UI element.

enter image description here

So in your third image you show a similar tree but what happened to the Template GameObject? It appears you deleted this and replaced it with the Finances GameObject. This is your primary issue. You can't delete this Template GameObject portion of the Dropdown GameObject. The Template is utilized by the Dropdown code in order to further determine the style of the Dropdown you'll see while in game as well as provide you with a template to look at. I don't know all of the internals of how this works, but I know it for sure plays a roll in your issue.

enter image description here

I know this because now take a look at my Dropdown component. Look at the Template field in mine and compare it to yours. Your's is filled with Finances rather than Template, which is the reason that your Dropdown populates with fields from the Finances rather than the values you are trying to pass it.

Here is what I suggest you do. I'm assuming that the FinancesTab, InventoryTab and StatsTab are all UI elements you want to open upon clicking the respective Dropdown item. If that is the case:

  1. Create a new Dropdown GameObject
  2. Don't delete the Template GameObject within it and leave the Template field in the Dropdown GameObject as is
  3. Add a script that utilizes the SetActive function for each UI element (place them in public fields) to the Dropdown GameObject
  4. Set this code up so that when a certain item on the Dropdown is selected, it sets the desired UI Tab to SetActive(true);
  5. Now reference the new script in the OnValueChanged(Int32) field and reference the correct Method from that script in the dropdown menu in the OnValueChanged(Int32) field.

I believe this should solve your problem and help you achieve what you want. Take a look at the Dropdown API and this Youtube tutorial on Dropdowns if my steps are confusing. You can definitely achieve what you want by following those two links (that's how I figured them out!).

Hope this helps!

Your caption is the gameobject 'Label' so its defaulting that in the dropdown because there are no sprites. I'm guessing Label has a text component that says 'Money'?

enter image description here

Related