Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Screen.currentResolution not working in build correctly

Discussion in 'Editor & General Support' started by NataliyaMilchenko, Jun 28, 2017.

  1. NataliyaMilchenko

    NataliyaMilchenko

    Joined:
    Dec 15, 2014
    Posts:
    2
    Screen.currentResolution and Screen.width / Screen.height not working in build.
    It's not working in unity as it might work. In editor everything works perfectly. For example I have a fullHD display and Screen.currentResolution IN EDITOR returns me 1920 * 1080 and Screen.width plus Screen.height return the editor game window resolution 511 * 909. But IN BUILD both of them returns incorrect resolution. For me it's sometimes 1080 * 1080 that I can't even define if screen horizontal or vertical. Sometimes it's 1024 * 768, better but not 1920 * 1080.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    What version of Unity are you using? Have you filed a bug report?
     
  3. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,362
    I also just submitted a bug report for this. It works on Mac and Unity 4.7. But not for Windows and Unity 5.6.4f

    When in a fullscreen window it reports the wrong value for Screen.currentResolution.width and height.

    breaking code from Unity 4.7

    Is there a workaround to get the screen resolution on windows for C sharp? What I want is when people go into fullscreen mode using alt+enter I used to do:

    Screen.setResolution(Screen.currentResolution.width,Screen.currentResolution.height,true)

    but now this doesn't work. Without doing this it just in the wrong resolution with black bars at the sides or top and bottom.
     
  4. NataliyaMilchenko

    NataliyaMilchenko

    Joined:
    Dec 15, 2014
    Posts:
    2
    I resolved this problem using C# to get full screen size

    System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
    System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height

    for desktop builds in windows it works perfectly
     
  5. wcburg1

    wcburg1

    Joined:
    Mar 23, 2018
    Posts:
    19
    2019.1.0.f1. I haven't filed a bug report, I didn't think it was a bug in the engine but maybe it is.
     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    I asked that 3 years ago ;)
    File a bug report and we can make sure it goes to the right people who can tell you if it's a bug or not. And fix it if it is :)
     
  7. wcburg1

    wcburg1

    Joined:
    Mar 23, 2018
    Posts:
    19
    Holy S*** I'm a dumbass. I just asked a really similar question and had this open in a tab so I thought it was my question with a bunch of replies. :rolleyes:
     
    PraetorBlue and karl_jones like this.
  8. A_Marraff

    A_Marraff

    Joined:
    Dec 12, 2015
    Posts:
    5
    Having the same issue in Unity 2019.4.17f and was looking for an answer. My screen is 1440p and the editor detects that, but the build only sees 640x480. It's a bug and has been fixed in recent Unity versions. https://issuetracker.unity3d.com/is...t-resolutions-differ-between-editor-and-build

    Edit 1: Workaround: Instead of Screen.Resolution, use Display.main. For example, Display.main.systemWidth instead of Screen.currentResolution.width.

    Answer found here: https://stackoverflow.com/questions/33117150/screen-currentresolution-with-unity-5-2-1

    Edit 2: Turns out that the real issue is that Screen.currentResolution.refreshRate returns differently in-editor vs. in-build. In-editor, the refresh rate will be the exact refresh rate of your monitor, say 120Hz. But, in-build, the value will return 119Hz. Therefore, when I was comparing the resolution strings, they were only equal in the editor because of this. So, in-build, the script skipped over my resolution assignment code and defaulted to the dropdown's first option (640x480). So, ensure you compensate for the difference of 1 somewhere in your code! That fixed it for me.
     
    Last edited: Mar 3, 2023