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 jcam828 · Dec 07, 2019 at 03:36 AM · displaydropdownqualitysettings

Graphics quality dropdown saves playerpref but displays default?

Hello. I don't write code, but I got help to get this far. I probably just need one or two lines of code to finish this if you don't mind. I created a TextMeshPro dropdown on the Settings Menu canvas to allow users to select Quality setting. I thought it wasn't working, because testing in Unity, if I went from Menu scene to Game Play scene and back, the dropdown text and dropdown value in the Inspector had reset to the default. But a PC build showed me otherwise based on the screen going black if I chose any setting except the most recent. So, it seems that all is working and saving fine except what is being displayed in the dropdown if I leave the Menu scene and return. The setting is saving fine after quitting the game and restarting as well. What exactly do I need to add to this code to make the dropdown not display the default after leaving the Menu scene? Here are the two scripts handling this. The first is attached to the dropdown itself. The second is attached to a canvas in the opening splash scene that lasts only a few seconds. Thank you! using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class SettingsMenu : MonoBehaviour
 { 
     public void SetQuality (int qualityIndex)
     {
         QualitySettings.SetQualityLevel(qualityIndex);
         PlayerPrefs.SetInt("_qualityIndex", qualityIndex); 
     }
 }

Here's the second script: using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class GraphicsQualitySave : MonoBehaviour
 {
     void Start()
     {
         LoadQuality();
     }
     private void LoadQuality()
     {
         if (PlayerPrefs.HasKey("_qualityIndex"))
         {
             int qualityIndex = PlayerPrefs.GetInt("_qualityIndex");
             QualitySettings.SetQualityLevel(qualityIndex);
         }
     }
 }
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
1

Answer by Larry-Dietz · Dec 07, 2019 at 03:54 AM

In your menu screen, in a Start method, you need to read the value from PlayerPrefs, the same as you are in that 2nd script, then set the dropdown to display whichever entry is for the quality you got from PlayerPrefs.

To do this, your SettingsMenu class will need a reference to the dropdown.

Try changing your script to this...

  public class SettingsMenu : MonoBehaviour
  { 
     public TMPro.TMP_Dropdown QualityDropDown;
 
     void Start()
     {
         int Quality=PlayerPrefs.GetInt("_qualityIndex", 0);
         QualityDropDown.value = Quality;
     }
 
      public void SetQuality (int qualityIndex)
      {
          QualitySettings.SetQualityLevel(qualityIndex);
          PlayerPrefs.SetInt("_qualityIndex", qualityIndex); 
      }
  }

Presuming that the quality index you are saving is the actual index of the item in the dropdown, then I believe this should work.

Just make sure you drag the DropDown into the field in the inspector.

Hope this helps, -Larry

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 jcam828 · Dec 07, 2019 at 04:21 AM

Thank you so much, Larry. It isn't working yet. I changed the script and saved it, but please excuse my ignorance. I don't know what you mean by dragging the DropDown into the field in the inspector. I don't see a field to drag it to. I tried dragging it into the Inspector field for On Value Changed (Int32), but that didn't work because the actual quality didn't change at all when I went through playing in Unity. Unless I'm choosing the wrong function. I chose "value" at the top. So I put the Settings Canvas back in that field rather than the dropdown. What am I missing?

Comment
Add comment · Show 4 · 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 jcam828 · Dec 07, 2019 at 04:43 AM 0
Share

To clarify, the Settings$$anonymous$$enu script was originally a component of the Settings Canvas. I just experimented and realize that copying that script to the T$$anonymous$$P dropdown object works too. So I can keep it there, but it does the same as before---saving quality setting but resetting to default dropdown value.

Edit: I also get the following error in the console when I press play and click button to switch from $$anonymous$$ain $$anonymous$$enu canvas to the Settings $$anonymous$$enu canvas: NullReferenceException: Object reference not set to an instance of an object Settings$$anonymous$$enu.Start () (at Assets/Scripts/Settings$$anonymous$$enu.cs:12)

avatar image Larry-Dietz · Dec 07, 2019 at 03:04 PM 0
Share

Whichever object this script is attached to, when selected in the scene view, should show this script as a component in the inspector. In that component, you should see a field named QualityDropDown, and it should currently be set to None. While this is visible to you, click on the actual dropdown object in scene view, and drag in to the component, replacing the None, with the actual dropdown object.

Once you have the component assigned, as above, your null reference error should go away as well.

avatar image jcam828 Larry-Dietz · Dec 07, 2019 at 03:15 PM 0
Share

That did it! Thank you so much for being here and so quickly responding with exactly what I needed, Larry! Take care.

avatar image Larry-Dietz jcam828 · Dec 07, 2019 at 03:31 PM 0
Share

You are very welcome. Glad I was able to help.

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

189 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 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 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

How to display text from a text object to another text object? 1 Answer

Canvas behaves differently on PC fullscreen and WebGL fullscreen 0 Answers

How to fit content into a specified area of screen at game startup 1 Answer

Reserve ammo not displaying on UI 0 Answers

Re-order the items of dropdown list using DragHandler 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