Screen.SetResolution and full screen not behaving correctly

Hi all,

As the title says, I’m having a problem with using Screen.SetResolution(…).

When in fullscreen mode, and calling Screen.SetResolution(1024, 768, false), the game will exit fullscreen mode but the resolution will not be applied and appears to revert to 640x480 (more on that below…). If you then change the resolution again while in the windowed mode, the resolution will change to the appropriate windowed resolution.

I’m disabling the ‘Display Resolution Dialog’ in the player settings, so that all the resolution settings are handled inside the game.
I have noticed that when I enable the dialog to test, it defaults to 640x480… In-game, the resolution gets set to whatever the current desktop resolution is if it can’t find a custom saved resolution setting. So if you were to specify 1280x720 in the unity dialogue (for testing purposes) then the game would still default to the current desktop resolution, but if you toggle to windowed mode, it will revert to 1280x720, not the specified resolution.

This is on OSX. I know OSX handles fullscreen differently to windows so I’m not sure if that’s playing a part here.

TL/DR: Resolution changes are not being applied when going from fullscreen to windowed mode.

Thanks for your time,
Sam

Just thought I’d add an answer to my own question here…

Looks like they still haven’t fixed this one, but I managed to find a work around. There’s a problem with changing the resolution and full screen settings in the same frame. I worked around it by using a coroutine and waiting for a frame or so in between changing each setting, like so —

    private IEnumerator WaitForScreenChange(bool fullscreen)
    {
        int width = Screen.width;
        int height = Screen.height;

        Screen.fullScreen = fullscreen;

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

        Screen.SetResolution(width, height, Screen.fullScreen);
    }

Have you tried to change fullScreen before SetResolution (store the current Screen Width/Height before)?

Why don’t you just use your function’s parameter “fullScreen” as an argument to Screen.SetResolution()?

Screen.SetResolution(width, height, fullScreen);

// instead of

Screen.SetResolution(width, height, Screen.fullScreen);

Also, it feels like you don’t need to set Screen.fullScreen at all since changing the resolution sets the full screen mode too. So you end up with this one line only:

Screen.SetResolution(width, height, fullScreen);

This way, you completely avoid this Unity’s annoyance.