Search Unity

Screen.SetResolution Reports wrong Resolution (1024x768)

Discussion in 'General Graphics' started by aivo, Jun 9, 2020.

  1. aivo

    aivo

    Joined:
    Feb 13, 2017
    Posts:
    30
    Hi there

    I want my application to go fullscreen in a resolution of 1920x1080. This happens in a controlled envrionment, where 1920x1080 is the only possible resolution and Win10 itself always starts correctly with this resolution.
    Im using unity 2019.2.8f1.

    Sometimes the application start quite weirdly and reports a resolution of 1024x756. this is how it looks like:

    upload_2020-6-9_11-13-53.png

    left is correct, right is wrong. I also don't know, why the wrong screen shows this black border around the actual game.


    I have the following code:

    Code (CSharp):
    1.     Screen.fullScreenMode = FullScreenMode.FullScreenWindow;
    2.         Debug.Log("resolution set");
    3.         Screen.SetResolution(1080, 1920,true);
    4.         Debug.Log("Fullscreen Debug: " + Screen.width + " | " + Screen.height);
    5.         Debug.Log("Fullscreen Debug: " + Screen.fullScreenMode + " | " + Screen.safeArea);
    whereas this is how the log looks like:

    upload_2020-6-9_10-56-37.png

    Anyone has encountered similar issues? I really don't know how I could improve my code regading this issue, as a restart resolves this issue. Is this a known bug? Also I would really like to know why unity generates this black border mentioned above.
     
    Last edited: Jun 9, 2020
  2. aivo

    aivo

    Joined:
    Feb 13, 2017
    Posts:
    30
    actually what I've written above is not entirely true. Accroding to my observation the following happend.

    1. for some unknow reason, my game started in the fallbackresolution (1024x768)
    2. although the game started in the wrong resolution, during the Start() method Screen.width and Screen.height report the resoltuion (1920x1080) that has been tried to set manually via Screen.SetResolution.
    3. when I quit the game, regedit has stored the actual (undesired) resolution of 1024x768 regeditreport.png
    4. When I restart the game, it starts in the correct resolution
    5. This time, Screen.width and Screen.height report during the Start() method the wrong resoltuion (1024x768), although the game started correctly.
    6. when I quit the game, regedit shows the correct settings.


    Can I therefore conclude, that the Resolution PlayerPrefs are last written when the game quits?
     
  3. weareinteractive

    weareinteractive

    Joined:
    Apr 14, 2017
    Posts:
    12
    Same problem here. I found out that this happens when the executable opens before the screen turns on or if the video cable is unplugged during the application was running.
    After that, one of the solutions to fix this is to delete the regedit file.

    So I don't know if it is a communication problem between unity and the operating system after a writing/read file error??
     
    Last edited: Sep 29, 2020
  4. aivo

    aivo

    Joined:
    Feb 13, 2017
    Posts:
    30
    On my side I found what was causing the error: a few of the 50 screens we installed, had a weekly restart in the (hidden) system settings (thanks Samsung grrr, that was not an easy find). So while these screens were running, every week at the same time they rebootet. This caused unity to loose the FullHD resolution and switching back to the fallback resolution.

    so, @weareinteractive, what you describe makes perfectly sense. And yes, deleting the regedit file ensures that the application starts correctly.