Screen.SetResolution ineffective

Hi,
Using Screen.SetResolution (in conjunction with a dropdown and a toggle in a settings menu) to allow the player to set res ingame.
However, while testing this is doing…nothing. Ive got an ingame error log, there are no errors appearing, and my debug.log at the end is appearing, but the window itself is not changing.

In this code (below), the initial idea was to get the input, pass it into Screen.SetResolution, along with whether to allow fullscreen. This would happen when the player presses the apply button.

The print statement at the end is calling, so i know the function is going through.

I commented out my initial try, and did a call to just make it 1910x1080 fullscreen, but no luck.

Tried using the ScreenChange enumerator to use that trick of setting fullscreen, waiting 2 frames then applying screen.setresolution but again, nope.

public void OnApply ()
    {
        string selectedRes = resolutionSelectField.options[resolutionSelectField.selectedOptionIndex];
        if (selectedRes != Screen.currentResolution.ToString())
        {
            string[] alteredSelected = selectedRes.Split(new char[] { 'x', ' ', '@' });
            //StartCoroutine(ScreenChange(int.Parse(alteredSelected[0]), int.Parse(alteredSelected[1]), fullScreenToggle.isOn));
            //Screen.SetResolution(int.Parse(alteredSelected[0]), int.Parse(alteredSelected[1]), fullScreenToggle.isOn);
            Screen.SetResolution(1920, 1080, true);
        }

        print("Set res to " + selectedRes + " and fullscreen mode = " + fullScreenToggle.isOn);
    }

    private IEnumerator ScreenChange(int w, int h, bool fullscreen)
    {
        Screen.fullScreen = fullscreen;

        yield return new WaitForEndOfFrame();
        yield return new WaitForEndOfFrame();

        Screen.SetResolution(w, h, Screen.fullScreen);
        yield break;
    }

Thanks all!

You know it reached the end of the function, but do you know if the code in the if block ran? I would put the print statement in there, right after the call to SetResolution.

1 Like

Of course. Because that would be the smart, rational thing to do.

It’s midnight, thank you so much, I’ll let you know how it goes in the morning.

Couldnt wait for morning. That ‘!=’ was supposed to be ‘==’. Thanks @Scabbage , you’re a legend

Nice to see you got it solved :slight_smile: