Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
2
Question by sebj · Nov 01, 2015 at 12:20 PM · unity 5uidropdown

Dropdown will not change selected item text after changing options list at runtime

I have a Dropdown UI control. If I clear the options list and repopulate it, the text of the selected item is not changed.

It doesn't matter where or what the user clicks on, the only way to force the text to change is to alter the value member to a different value, and then put it back. This occurs when there is only one item in the new list, and when there is more than one. I have tried explicitly invoking OnValueChanged() but this still has no effect.

How do I force the Dropdown to reset/repaint/remove whatever caching its got after updating the options list?

I am resetting the options list like so:

     m_branchesDropdown.options.Clear();
     foreach (var branch in m_branches)
     {
         m_branchesDropdown.options.Add(new Dropdown.OptionData() { text = branch.name });
     }
Comment
Add comment · Show 2
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 neural · Nov 22, 2015 at 04:49 PM 0
Share

Hello sebj, did you find a solution to this?

avatar image viju · Feb 02, 2016 at 01:25 PM 0
Share

m_branchesDropdown.RefreshShownValue (); worked for me with little extra work to add the value to a string variable, I used string string optionselected = m_branchesDropdown.captionText.text

5 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by brandonhotdo · Nov 16, 2015 at 08:52 PM

I had this problem too but this seemed to fix it:

     int TempInt = m_branchesDropdown.value;
     m_branchesDropdown.value = m_branchesDropdown.value+1;
     m_branchesDropdown.value = TempInt;

Just put that after the foreach loop.

Comment
Add comment · Show 3 · 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 sebj · Nov 23, 2015 at 10:26 AM 0
Share

This is the solution I used. I was concerned that Unity required an iteration between setting it to another value then setting it back, but it doesn't so this work around is very unobtrusive!

avatar image jwvanderbeck · Apr 09, 2016 at 04:24 AM 1
Share

Sadly this workaround doesn't work if you only have one value in the new options list.

avatar image ArcticPinou · Mar 23, 2021 at 09:13 AM 0
Share

For me that's not the perfect solution because changing .value triggers the OnValueChanged event. I used "SetValueWithoutNotify" instead, and it worked.

avatar image
9

Answer by viju · Feb 02, 2016 at 01:24 PM

m_branchesDropdown.RefreshShownValue (); worked for me with little extra work to add the value to a string variable, I used string string optionselected = m_branchesDropdown.captionText.text

Comment
Add comment · 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
4

Answer by elliselkins · Sep 07, 2016 at 09:57 PM

There is a function called RefreshShownValue() on the dropdown that should be called.

Comment
Add comment · Show 1 · 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 TooManySugar · Mar 15, 2019 at 03:41 PM 0
Share

THAN$$anonymous$$ YOUUUUUUUUUUUUUUU!!!! I had the dropdown filled by script and the default selected item was not triggering any event, adding so it did. coool.

avatar image
2

Answer by flipwilson · Jul 12, 2016 at 05:34 PM

 ddProperty.value = 0;
 ddProperty.Select();
 ddProperty.RefreshShownValue();

Comment
Add comment · 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
1

Answer by neural · Nov 22, 2015 at 04:55 PM

Ok just found the solution to this:

 m_branchesDropdown.transform.FindChild("Put_Your_Caption_Text_Here").GetComponent<Text>().text = m_branchesDropdown.options[m_branchesDropdown.value].text;
Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

53 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

Related Questions

EventSystem doesn't like dropdown 0 Answers

Where to find the new Dropdown menu 0 Answers

How can I extend an UI Component and change it's default values when added on editor? 0 Answers

Dropdown list hiding under background layer 0 Answers

UI buttons sometimes does not detect touch 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