Search Unity

Resolution dropdown shows same resolutions

Discussion in 'Scripting' started by b4gieta, Jan 15, 2020.

  1. b4gieta

    b4gieta

    Joined:
    Jul 17, 2018
    Posts:
    97
    Hi
    I made this script using tutorial. It works well in the Editor, but when I build my game, resolution in dropdown are multiple. For example, there are four 1920x1080 etc. What's the problem?

    Code (CSharp):
    1. public Dropdown dropdownMenu;
    2. void Start()
    3.     {
    4.  
    5.         resolutions = Screen.resolutions;
    6.         dropdownMenu.onValueChanged.AddListener(delegate { Screen.SetResolution(resolutions[dropdownMenu.value].width, resolutions[dropdownMenu.value].height, Screen.fullScreen); });
    7.         for (int i = 0; i < resolutions.Length; i++)
    8.         {
    9.             dropdownMenu.options[i].text = ResToString(resolutions[i]);
    10.             dropdownMenu.value = i;
    11.             dropdownMenu.options.Add(new Dropdown.OptionData(dropdownMenu.options[i].text));
    12.  
    13.         }
    14.     }
    15.  
    16.     string ResToString(Resolution res)
    17.     {
    18.         return res.width + " x " + res.height;
    19.     }
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Take a look at the Resolution class in the documentation. You've got width and height, of course, but you also have refresh rate. I guarantee you that the four 1920x1080's all have different refresh rates.
     
    Joe-Censored likes this.
  3. b4gieta

    b4gieta

    Joined:
    Jul 17, 2018
    Posts:
    97
    Yeah, that's it. But why does 1920x1080 has twice 60 Hz? And why there are resolutions that have one or two refresh rates?
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    The information comes from your monitor, so we can only speculate what your monitor is returning. It might support two different refresh rates both very close to 60 Hz that are both rounded to the same number. It might actually be returning the same resolution/refresh twice and Unity is just passing that on through. As for why some resolutions have more than one refresh rate and others only have one, that just comes down to the hardware capabilities of your specific monitor.

    You probably will want to implement your own filtering of the list if this bothers you. I'd expect some super cheap monitors may return even more silly of results.