Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Quality Level index?

Discussion in 'Scripting' started by Riderfan, Jun 1, 2017.

  1. Riderfan

    Riderfan

    Joined:
    Jan 10, 2013
    Posts:
    514
    Hello.

    I'm trying to switch some features on or off depending on the player's currently selected Quality setting. There's an API to tell you the setting, but there seems to be nothing to tell you want setting is what index.

    Code (CSharp):
    1.  
    2.             //Only use a SAO for the highest quality level.
    3.             int QualityLevel = QualitySettings.GetQualityLevel();
    4.             if (QualityLevel > 0)
    5.                 mSAO.Enabled = false;
    6.  
    As you can see in that code, there's no way for me to know what setting is level 0.
    How do I match the quality level setting established via the QualitySettings panel to the index the API returns?

    thanks
     
    Roman_Keivan likes this.
  2. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,302
    Make an enum
     
    Roman_Keivan likes this.
  3. Riderfan

    Riderfan

    Joined:
    Jan 10, 2013
    Posts:
    514
    well, yeah, no kidding... but what index of the enumerator goes with what index on the PlayerSettings panel? There's no indicator on the settings panel tell you want index is what. Is the first one 0, the last one? Are they even zero based?
     
    Roman_Keivan likes this.
  4. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,302
    Can't you just note the quality level you have selected in the panel, and then ask it what index it is in game?
     
    Last edited: Jun 1, 2017
    Roman_Keivan likes this.
  5. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,133
    0 is the first (lowest) quality level, and it goes up. You can get the highest quality level index through
    Code (CSharp):
    1. QualityPresets.Presets.Count;
    The corresponding names could be retrieved in such a manner:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ExampleClass : MonoBehaviour {
    5.  
    6.     public string[] names;
    7.  
    8.     void Example() {
    9.         names = QualitySettings.names;
    10.     }
    11. }
    12.  
     
  6. Riderfan

    Riderfan

    Joined:
    Jan 10, 2013
    Posts:
    514
    Excellent.. thanks.. exactly what I was after.
     
    Roman_Keivan likes this.
  7. Julien-Lynge

    Julien-Lynge

    Joined:
    Nov 5, 2010
    Posts:
    142
    As of 2019.x, this no longer works. The new way to get the preset count that I could find was:

    Code (CSharp):
    1. QualitySettings.names.Length