Resolution Drop down Menu, Duplicates because of refresh rate

Hello,

I created a menu so players can change resolution.
In the editor it’s fine and only shows options of 165 hz refresh rate, but when I build the game I get a full list as you can see on the image that includes every refresh rate option.
What is the best way around this?
I want to have a list with only resolutions using the current refresh rate the user has. Just like it does in the editor.

Just filter out any Resolutions that don’t have the refresh rate you want. https://docs.unity3d.com/ScriptReference/Resolution-refreshRate.html

How do I know what refresh rate I want? I don’t know what sort of refresh rates people have. I don’t mind 75, 90, 120 etc. I just want one option and thats the refresh rate they use in general.
Do I have to go through them all and remove the lowest onces?
Just seem like a thing that should be easier to get around.

Honestly, that sounds like a good argument not to filter out certain refresh rates to me. Why not give the user all the options?

A few possibilities I can think of:

  • Look at the current refresh rate from Screen.currentResolution: https://docs.unity3d.com/ScriptReference/Screen-currentResolution.html. Filter out any that aren’t the same as that.
  • Look at all of the resolutions from Screen.resolutions, pick the highest refresh rate, and only show resolutions with that highest rate*.*
  • Maybe do a hybrid approach. Pick 1. or 2., but give the user a checkbox like “show all refresh rates”, which will update the list to include all of them.

Sounds good, I will try that way next time I’m working on the project :slight_smile:
thanks for good input!
Just throwing it out there - The reason I don’t want to show all is because people might have a list like mine, where its +140 different choices. It looks kinda bad :slight_smile:

how to filter the resolutions that contain the refrrshrate 45hz ?

Inspect the refresh rate field on the Resolution struct and filter out whichever resolutions you need: https://docs.unity3d.com/ScriptReference/Resolution-refreshRate.html

I’m running into the exact same problem. Did you figure out a solution that worked for you? I’ve tried different things to try and remove any refresh rates that don’t match the current refresh rate but can’t seem to get it to work. So I start working on other stuff and every time I come back to this problem I can’t seem to make any progress.

Hey, It’s a old project I havne’t touched in a while but this is what I found.
The code ain’t pretty, but it did the job. Hope it helps
Lists:

    List<Resolution> resolutions = new List<Resolution>();
  1. Add all resolutions in a list (distinct)
    void AddResolutions()
    {
        if (resolutions == null || resolutions.Count == 0)
        {
            resolutions.AddRange(Screen.resolutions.ToList().Distinct());
        }

        resolutions = resolutions.OrderByDescending(i => i.width).ToList();
    }
  1. Fix Resolution dropdown menu
    void FixResolutionDropdown()
    {
        List<string> options = new List<string>();
        string option;
        int currentResolutionIndex = 0;

        int refreshRate = refreshRates[refreshRateDropdown.value];
        List<Resolution> resolutionsOptions = new List<Resolution>();
        resolutionsOptions.AddRange(resolutions.Where(resolution => resolution.refreshRate == refreshRate).ToList());

        int i = 0;
        foreach (Resolution resolution in resolutionsOptions)
        {
            option = resolution.width + " x " + resolution.height;// + ", " + resolution.refreshRate + " hz";
            options.Add(option);
            if (resolutionsOptions[i].width == Screen.width && resolutionsOptions[i].height == Screen.height)
                currentResolutionIndex = i;
            i++;
        }

        resolutionDropdown.ClearOptions();
        resolutionDropdown.AddOptions(options);
        resolutionDropdown.value = currentResolutionIndex;
        resolutionDropdown.RefreshShownValue();
    }

Tried your scipt but it somehow didnt find refreshRates. Sry im new

Can someone tell me what i made wrong pls

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Linq;

public class Options : MonoBehaviour
{
public TMP_Dropdown resolutionDropdown;

public TMP_Dropdown refreshRateDropdown;

List resolutions = new List();

void AddResolutions()
{
if (resolutions == null || resolutions.Count == 0)
{
resolutions.AddRange(Screen.resolutions.ToList().Distinct());
}

resolutions = resolutions.OrderByDescending(i => i.width).ToList();
}

void FixResolutionDropdown()
{
List options = new List();
string option;
int currentResolutionIndex = 0;

int refreshRate = refreshRates[refreshRateDropdown.value];
List resolutionsOptions = new List();
resolutionsOptions.AddRange(resolutions.Where(resolution => resolution.refreshRate == refreshRate).ToList());

int i = 0;
foreach (Resolution resolution in resolutionsOptions)
{
option = resolution.width + " x " + resolution.height;// + “, " + resolution.refreshRate + " hz”;
options.Add(option);
if (resolutionsOptions_.width == Screen.width && resolutionsOptions*.height == Screen.height)_
currentResolutionIndex = i;
i++;
_
}_
resolutionDropdown.ClearOptions();
resolutionDropdown.AddOptions(options);
resolutionDropdown.value = currentResolutionIndex;
resolutionDropdown.RefreshShownValue();
_
}*_

Hello there! I saw this here while I was working on this issue recently. khold93, could you please share with me the code you created to start this discussion?

You wrote a really nice code and it would be great if I could reach that code right now.

I would be very happy if you share the code with me. good day!

(this =
)

7423265--908525--C7TLTlS.png