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 lpayson · Nov 30, 2015 at 12:45 AM · user interfacedropdown

How can I find a dropdown menu game object from a script?

Hello all, I've created a canvas with a dropdown menu in the editor, it's there sitting in my Hierarchy window staring at me, but I cannot for the life of me figure out how to reference that from script.

I need to pass the value of the drop down menu to a function so I assume I need SOMETHING.value but I don't know what that something is. I tried (Dropdown)GameObject.Find("myDropdown") and was told that i can't convert from a game object to a dropdown :(

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

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Rajeesh_AR · Nov 30, 2015 at 12:20 PM

Hi, I am not sure about your script. Still did you add "using UnityEngine.UI;" to the script. If not add that and check. If this doesn't solve your issue, please share your script, so that I will check and help you. Thanks.

Comment
Add comment · Show 2 · 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 KdRWaylander · Nov 30, 2015 at 12:49 PM 1
Share

The man is right. And you can't cast a GameObject as a Dropdown, since one is a gameobject ... and the other a dropdown CO$$anonymous$$PONENT.

So what you want to call is in fact:

 Dropdown uiDropdown = GameObject.Find("myDropdown").GetComponent<Dropdown>();
avatar image bblay KdRWaylander · Jan 01, 2016 at 12:04 PM 0
Share

Thanks, Rajeesh_AR and $$anonymous$$dRWaylander, your combined solution worked.

avatar image
0

Answer by epistomai · May 25, 2016 at 10:34 PM

I was looking for this answer, I had exactly the same question. But now, how can I retrieve the value from the options instead of the value of the index? Meaning, if in the first option (index is 0) is "This" (string for example)

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
0

Answer by dzne_weiss · Nov 03, 2016 at 01:39 PM

@epistomai

You would do it something like that:

  Dropdown uiDropdown = GameObject.Find("myDropdown").GetComponent<Dropdown>();

and then:

 string chosenValue = uiDropdown.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

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

37 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

Related Questions

UI Canvas draw order 1 Answer

Tutorial for Dropdown item needed 1 Answer

DropDown with Text Input capabilities 0 Answers

Search in Dropdown options 2 Answers

How would I go about comparing input from a InputField to a array? 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