Search Unity

PlayerPrefs for Screen Resolution ignored in Windows builds

Discussion in 'Editor & General Support' started by Harry1960, Jul 4, 2008.

  1. Harry1960

    Harry1960

    Joined:
    May 15, 2007
    Posts:
    136
    In our project we've disabled the display of the resoultion dialog. Even if we change the screens settings via PlayerPrefs.SetInt("Screenmanager Resolution Width", 640) and PlayerPrefs.SetInt("Screenmanager Resolution Height", 480) or manually via the registry editor the new values are ignored at startup and the inital values of 'Player Settings' 'Default Screen Width' and 'Default Screen Height' are used instead.
    Is there any workaround for that behaviour instead of setting those values via script SetResoluation() (which causes screen flickering) at startup of the application?
     
  2. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    I'm having this exact same problem. Did you ever get it resolved?
     
  3. Harry1960

    Harry1960

    Joined:
    May 15, 2007
    Posts:
    136
    We use a config file for our application and when the app starts, we set the screen resolution manually with Screen.SetResolution().
     
  4. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Blimey. I was hoping you wouldn't say that. Switching res twice is a problem for my project. I've noticed that apps that use the regular resolution selection dialog don't have this problem, which makes me think that these settings are JUST getting set in the registry, but are being stored somewhere else as well. This is corroborated by tests I've done on the Mac that show that it is getting persistent settings information from somewhere even after I've deleted the preference file.
     
  5. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I'm noticing this `issue` also. When the dialog window is disabled it seems to always pull from the default as set up in the editor, and writes out a new set of preferences to the registry even if it never reads them. It would be nice if we can change the registry externally and then have unity actually read the file (without the dialog) and use those settings. But alas I think it's not designed for that?

    No matter what I've tried I can't get it to use the settings I put into the external file, unless perhaps the dialog is displayed, but that defeats the purpose.
     
  6. Harry1960

    Harry1960

    Joined:
    May 15, 2007
    Posts:
    136
    You have to do that in your start screen when resoluation shouldn't matter that much.
    You can find the setting in the registry under HK_CURRENTUSER\YourCompany\ApplicationName.
     
  7. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Yah I know it's in the registry but no matter what is set in the registry it has no effect on how the application shows. I tried changing it externally and Unity just insists on overwriting whatever changes I made with its defaults.
     
  8. Harry1960

    Harry1960

    Joined:
    May 15, 2007
    Posts:
    136
    Jep - that's why we change the screen resolution manually in the start screen - it's just a bug that never got fixed!
     
    AlanMattano likes this.
  9. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Yah that's what I'm going to have to do, start up in a high resolution (probably the desktop resolution in most cases, and the one in which the unity logo looks `normal`), and then adjust the resolution in script if needed. Not ideal, because it means that in order to, for example, start up in windowed mode sometimes but not always, I have to have 2 separate versions of the app.
     
  10. FierceForm

    FierceForm

    Joined:
    Jun 25, 2010
    Posts:
    124
    This is still happening. Is there any chance of this getting fixed soon?
     
  11. sh0v0r

    sh0v0r

    Joined:
    Nov 29, 2010
    Posts:
    325
    Yes... is it going to get fixed, I just encountered this also ...
     
  12. Otto@WoWiWe

    Otto@WoWiWe

    Joined:
    Aug 25, 2011
    Posts:
    2
    It looks like this is still a problem... I ran into it myself and found a bug suggestion on the Unity feedback site to vote for.
     
  13. vladk

    vladk

    Joined:
    Jul 10, 2008
    Posts:
    167
    oh my god, this is so pathetic! This lousy bug exists for 3 (!!!) years and still not fixed! Guys, are you kidding us!?
     
  14. sh0v0r

    sh0v0r

    Joined:
    Nov 29, 2010
    Posts:
    325
    I get the impression that fixing anything involving the Stand alone player generally is a lower priority to Mobile and Web platforms.

    I have written my own in game Screen Mode UI which is pointless because of this issue.

    Another example: the InputManager is less than ideal for games that want to configure their own controls in game and there is still a bug in the GetRawInput function that returns bad data and can only be fixed by changing the Players registry setting to use DirectInput. A fix that is undocumented...
     
  15. Lohoris2

    Lohoris2

    Joined:
    Aug 20, 2013
    Posts:
    85
    Now, 5 years later…
     
  16. AR_Rizvi

    AR_Rizvi

    Joined:
    Aug 12, 2013
    Posts:
    40
    Now 8 Years and not solved
     
  17. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,900
    Bug report with repro project please, otherwise it won't be fixed.
     
  18. gheeler

    gheeler

    Joined:
    Nov 7, 2012
    Posts:
    18
    This works fine for me. I haven't tested a lot but have you checked if the resolution you are trying conforms with your supported aspect ratios in the Resolution and Presentation section of the PC player settings.
     
  19. AR_Rizvi

    AR_Rizvi

    Joined:
    Aug 12, 2013
    Posts:
    40
    Yes i did that Exactly i get all the supported resolutions and the setting it afterwards by users choice
     
  20. mmsteve

    mmsteve

    Joined:
    Aug 7, 2017
    Posts:
    12
    This still doesn't work properly. You cannot configure these settings and enforce a specific display resolution through the player build settings.
     
  21. arkogelul

    arkogelul

    Joined:
    Nov 14, 2016
    Posts:
    105
    I'm using 2017.2 and I can bypass the resolution stored in the register with Screen.SetResolution. But the splash screen will still use the stored resolution.

    Say I use Screen.SetResolution(1920, 1080, true);
    I'm launching my game with my screen set to 800*600 it will save this resolution (800*600) in :

    HKEY_CURRENT_USER ->Software->""Company Name"->"Produc Name"

    If I set my screen resolution to a larger one, 1600*900 for exemple, the game will launch at 800*600 and once the (blurry and squary) splash screen is over, the game will switch to the forced resolution (with Screen.SetResolution(1920, 1080, true); ).

    Is there a way to force a resolution in the register to prevent this splash screen issue ?
     
  22. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Now, 10 years later…

    @Tomas1856 We reported the bug and we voted

    If I submit a bug probably will tell me: is too late or is duplicated. And that is bad.
    We need a solution for Unity5. This is a very old and important bug that is there probably since unity 1 up to Unity 2018.

    Here is one example: https://issuetracker.unity3d.com/is...when-default-is-native-resolution-is-selected

    It tells you that Severity is: 3 and Workaround is possible
    BUT there is no link to the Workaround solution and I didn't find a real solution
    Since Unity know, What is the Workaround solution for this bug?

    Probably in my experience You are not going to fix this problem since is in lates Unity 5.6.3p2
    I purchase Unity5 and I use it as a Launcher Updater so there is no repeated Unity intro splash screen,
    And is an important bug. I need my Unity5 pro app running from the start at that resolution. I'm not able to make my app resolution 800x600 since the first run no matter how hard I try for a week.
     
    Last edited: Feb 8, 2018
    Lohoris2 likes this.
  23. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
  24. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Last edited: Feb 23, 2018
  25. DaniyarGilymov

    DaniyarGilymov

    Joined:
    Dec 26, 2017
    Posts:
    14
    2018.2.6f1, issue is still exist, please fix it
     
  26. hsuchc8888

    hsuchc8888

    Joined:
    Jan 15, 2016
    Posts:
    8
    This issue still exists on 2019.1.0b3.
    #10YearChallenge
     
    DAh-Right and mohsennavazani like this.
  27. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    yep, having this issue on 2018.3.9. Set the resolution then a couple of scene changes later unity will decide that it wants to run native resolution and change to that. Tried disabling default native resolution in the player settings and this makes no difference either. It's like it just suddenly decides to just ignore anything the user has defined and just run native resolution. Somewhat disheartening to find this post 10 years later on and still talking about resolution changing issues.
     
  28. Discipol

    Discipol

    Joined:
    May 6, 2015
    Posts:
    83
    It is happening on 2019.3.0b4
     
  29. Talasas

    Talasas

    Joined:
    May 14, 2011
    Posts:
    8
    Seeing this on 2018.3.14f1

    If the registry key for Screenmanager Resolution Use Native is set to 1 this will occur, we can get it so bad that literally ilding the game for 20 seconds and it will switch back to native res, it's extremely apparent on a 4k monitor.

    Something we've also noticed when this happens is the windows task bar pops up for 1 frame, you can actually see it flash and then the resolution changes, today I also noticed that it happens if you switch the game to windowed mode. I'll let it sit there and the icon for the game in Win 10 flashes for a moment like it's going out of focus, except in plain window mode the size of the window doesn't change, only in fullscreen window mode. I'm wondering if there's some kind window management bug going here?

    Has anyone else noticed the flashing before the res changes back to native?
     
    Exbleative likes this.
  30. dojoman

    dojoman

    Joined:
    Jul 24, 2014
    Posts:
    278
    This solution is working for me:

    1. Set Player settings to "Fullscreen Window" with "default is native Resolution" = true.
    2. Delete Screenmanager Resolution Height / Width when you quit your application.

    Code (CSharp):
    1.     public static void QuitApplication () {
    2.        
    3.         PlayerPrefs.DeleteKey ("Screenmanager Resolution Height");
    4.         PlayerPrefs.DeleteKey ("Screenmanager Resolution Width");
    5.        
    6.         Application.Quit();
    7.        
    8.         #if UNITY_EDITOR
    9.         UnityEditor.EditorApplication.isPlaying = false;
    10.         #endif
    11.        
    12.     }
    That way i can always load the customer settings from other keys knowing the actual native resolution of the client monitor. This helps when your customer has set e.g. 1280x720 but his monitor is capable of 1920x1080 which you want to provide in a settings menu.
     
  31. aivo

    aivo

    Joined:
    Feb 13, 2017
    Posts:
    30
    I have not discovered this thread yet, so I created another one here a couple of days ago.
    The problem apparently still exists in 2019.2.8f1.
     
  32. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Congrats, the only working solution to me.
    (Maybe instead of deleting them you could also fill in the values you want for your startscreen...)
     
    Wappenull likes this.
  33. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    51
    Hi, internet traveller and lurkers, I'm from future!
    Just here to drop a quick copy-paste for another time travellers.

    I added this code to our option menu code, after Screen.SetResolution call we also set PlayerPrefs for next launch.
    Code (CSharp):
    1.  
    2. public static bool ApplyResolutionSettingsFromOptionMenu( int width, int height, FullScreenMode fs )
    3. {
    4.     // fs can be FullScreenMode.FullScreenWindow etc
    5.  
    6.    Debug.Log( $"Finally apply resolution {width} {height} {fs}" );
    7.    Screen.SetResolution( width, height, fs );
    8.  
    9.    // Note: to play nice on next EXE launch, also set this to registry
    10.    PlayerPrefs.SetInt( "Screenmanager Resolution Width", width );
    11.    PlayerPrefs.SetInt( "Screenmanager Resolution Width", height );
    12.    PlayerPrefs.SetInt( "Screenmanager Fullscreen mode", (int)fs );
    13.  
    14.     // Note the Screenmanager Fullscreen 'mode' is actually written in lower case
    15.     // This is not typo, I extracted this from regedit as-is.
    16. }
    17.  
     
    Last edited: Sep 6, 2022
  34. lorderu

    lorderu

    Joined:
    Dec 8, 2016
    Posts:
    2
    Unity 2022.3.10f1 about 15 years later.

    I changed from windowed to Fullscreen window in Project settings, then ran a build.
    It launched in fullscreen, then I changed back to windowed with a new resolution and it worked for me