Making a resolution menu

I am having a problem with the Resolution[ ] function that gets all resolutions supported by the monitor;

I created a variable to get the number of resolutions of my monitor:

Resolution[] resolutions;
public int resolutionsAmount;

void Start() {
resolutionsAmount = resolutions.Length;
}

Within Unity when I put the game to simulate, the ‘resolutionsAmount’ variable shows 11 resolutions that my monitor supports.

But then I compiled the game to see how everything is really working and to my surprise the ‘resolutionsAmount’ variable now is showing 15, not 11 anymore, as if suddenly my monitor supported 4 more resolutions.

I found that after I compile the game, it is showing a total of 15 resolutions because it is listing also the resolutions of 75Hz and not only the 60hz.

But within Unity at the time of simulating, ‘Resolution[ ]’ is giving me a list of 11 resolutions of only 60Hz.

How to list only 60Hz resolutions in Unity?

In theory if the QualitySettings.vSynchCount isn’t 0 the list should only contain the 60Hz resolutions. If you need to filter the results, the Resolution struct contains the refreshRate member so just filter your array through that.
https://docs.unity3d.com/ScriptReference/Screen-resolutions.html

1 Like

You just need to check the refresh rate as you add them to your list of resolutions. Below is code that checks if the refresh rate is between 59 and 60 (because sometimes 60Hz is reported to be 59Hz) before it adds it to the list.

List<Resolution> myresolutions = new List<Resolution>();

foreach (Resolution resolution in Screen.resolutions)
    if (resolution.refreshRate >= 59.0f && resolution.refreshRate <= 60.0f)
        myresolutions.Add(resolution);

By the way remember that thread where you only wanted certain aspect ratios? We can do that this way too.

List<Resolution> myresolutions = new List<Resolution>();

foreach (Resolution resolution in Screen.resolutions)
    if (resolution.refreshRate >= 59.0f && resolution.refreshRate <= 60.0f && resolution.width / resolution.height == 16 / 9)
        myresolutions.Add(resolution);
1 Like

Okay, it worked! Thanks!

My script with the menu to select resolution options looks like this:

public int resolution;
private List<Resolution> resolutionList;
private Resolution[] myResolutions;

void Awake() {
        Resolutions60Hz();
    }

public void Resolutions60Hz() {
        resolutionList = new List<Resolution>();

        foreach (Resolution res in Screen.resolutions) {
            if (res.refreshRate >= 59.0f && res.refreshRate <= 60.0f) {
                resolutionList.Add(res);
            }
        }
        myResolutions = resolutionList.ToArray();

        if (PlayerPrefs.HasKey("ResolucaoChave")) {
            resolution = PlayerPrefs.GetInt("ResolutionKey");
        }
        else {
            resolution = myResolutions.Length - 1;
        }
    }

void ResolutionOptions() {
        var optResolTxt = resolValue.GetComponent<Text>();

        if (Input.GetKeyDown(KeyCode.LeftArrow)) {
                if (resolucao > 0) {
                    resolution--;
                }
            }

            if (Input.GetKeyDown(KeyCode.RightArrow)) {
                if (resolucao < (myResolutions.Length - 1)) {
                    resolution++;
                }
            }

        if (screenMode == 1) {
            Screen.fullScreen = false;
        }

        if (screenMode == 2) {
            Screen.SetResolution(myResolutions[resolution].width, myResolutions[resolution].height, true);
            optResolTxt.text = myResolutions[resolution].width + " x " + myResolutions[resolution].height;
        }
    }

Now a question, does excluding from the game menu the 75Hz options of user monitor resolutions make any difference, considering that the game will run on multiple monitors?

And for a 2D pixel game, is it worth putting in the menu an option for graphics quality using QualitySettings.SetQualityLevel?
I thought about putting three options, LOW, MEDIUM and HIGH, but I don’t know if it makes any difference to a pixel game.

Locking the refresh rate to a lower value shouldn’t cause any problems, but it is worth pointing out that people who have one or more monitors with high refresh rates have bought them specifically because they don’t want to play at 60 Hz.

Just about every gamer I know has told me once you play high refresh rate you won’t want 60 Hz ever again.

1 Like

Hi, I was a long time without checking the answers here.
About your answer above, so is it better to keep the 75Hz resolution options, even for a pixel game?