Need help with Screen.currentResolution.width in full screen mode

I have a toggle in my options for Full Screen. Toggling it sets Screen.fullScreen = true/false. When my game is windowed, the Screen.width returns the window’s width as expected, and Screen.currentResolution.width returns 1920, my monitors current resolution.
8480915--1127540--upload_2022-9-30_15-20-57.png

The problem is that when I set Screen.fullScreen to true, Screen.currentResolution.width becomes the smaller window’s width. The game becomes letterboxed while at full screen. How do I “forget” those old window settings and just make the game run full screen?
8480915--1127534--upload_2022-9-30_15-20-36.png

8480915--1127537--upload_2022-9-30_15-20-47.png

Since Screen.currentResolution is only returning correct values while windowed, you need to switch to windowed mode, save the values from Screen.currentResolution, and then switch to fullscreen with those values.

void Awake()
{
    if (!PlayerPrefs.HasKey("MonitorResX") || !PlayerPrefs.HasKey("MonitorResY") || !PlayerPrefs.HasKey("MonitorRefreshRate"))
    {
        Screen.SetResolution(1280, 720, false);

        PlayerPrefs.SetInt("MonitorResX", Screen.currentResolution.x);
        PlayerPrefs.SetInt("MonitorResY", Screen.currentResolution.y);
        PlayerPrefs.SetInt("MonitorRefreshRate", Screen.currentResolution.refreshRate);
        PlayerPrefs.Save();

        Screen.SetResolution(PlayerPrefs.GetInt("MonitorResX"), PlayerPrefs.GetInt("MonitorResY"), true, PlayerPrefs.GetInt("MonitorRefreshRate"));
    }
}
1 Like

Thank you Ryiah. I have implemented a form of this solution and it’s working well.