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
0
Question by epic_ziver_D · Oct 21, 2016 at 09:52 AM · c#unity5

How to keep dropdown values after a scene switch or change them in a script

I'm using 3 scenes a menu scene, a settings scene and a game scene. In my settings scene some of my settings are using dropdowns but when ever I reload the scene it resets, I need it to stay the same, if I could change the values I could just have it change the value every load but I cant find out how to do it, I would greatly appreciate if anyone has a solution.

EDIT: I think some may not understand I need to know how to change the dropdown value, not how to store it. Also I want to change InputField text but I don't know how without it changing back.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Chethan007 · Jun 20, 2021 at 12:07 PM

@Landern I think this code might help you. I am in a similar situation where the skyBox I am changing in the setting menu. This is the part for the dropdown

 using UnityEngine;
 using UnityEngine.UI;
 
 
 public class DropDownSky : MonoBehaviour
 {
     public Dropdown dropDown;
     private void Start()
     {
         dropDown.value = PlayerPrefs.GetInt("DROPDOWNSKY");
 
         dropDown.onValueChanged.AddListener(delegate { DropdownItemSelected(dropDown); });//dropDown listener
     }
     public void DropdownItemSelected(Dropdown dropdown)//a delegate , a method which is invoked when the value of the dropdown is changed
     {
         switch(dropdown.value)
         {
             case 0: PlayerPrefs.SetInt("DROPDOWNSKY", 0);
                 break;
             case 1: PlayerPrefs.SetInt("DROPDOWNSKY", 1);
                 break;
             case 2:PlayerPrefs.SetInt("DROPDOWNSKY", 2);
                 break;
             case 3:PlayerPrefs.SetInt("DROPDOWNSKY", 3);
                 break;
             case 4:PlayerPrefs.SetInt("DROPDOWNSKY", 4);
                 break;
             case 5: PlayerPrefs.SetInt("DROPDOWNSKY", 5);
                 break;
         }
     }
 }
  

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 Landern · Oct 21, 2016 at 01:08 PM

Simple solution, use PlayerPrefs to save the DropDown.value for each drop down, retrieve it from PlayerPrefs when you load the screen or need that look up value. The value variable for DropDown controls is the index in the list of the item where 0 is the first item, 1 is the second and so on. Further more if you needed the text the DropDown.value corresponds to the OptionData list from DropDown.options and refers to the index in that list. I've linked all, the documentation that you should need.

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 epic_ziver_D · Oct 22, 2016 at 10:33 AM 0
Share

I don't think I explained myself, I need to know how to change DropDown.value

avatar image og52958 · Jan 23, 2021 at 08:42 PM 0
Share

@Landern Bro you helped me a lot. So In my settings menu there are 2 drop downs, quality and resolution. So according to your above reply, I can store dropdown values by using Dropdown.value in player prefs . Great. I'll be thankful to you if you send me a sample code. Thank you so much

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

7 People are following this question.

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

Related Questions

Movement Unit (RTS) 0 Answers

Car from Unity's standard assets giving me of null reference errors 0 Answers

How do I resolve, get_isActiveAndEnabled can only be called from the main thread error 1 Answer

How do you move the camera with the player. Whats wrong with my code? 0 Answers

Gravity problem 1 Answer


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