• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Laumania · Nov 17, 2019 at 01:40 PM · screen resolution

Mismatch refreshrate/hz between currentResolution and possible resolution?

Hi

I'm building a settings UI for my game and want a dropdown with possible resolutions and of cause want the current resolution be selected by default - pretty standard.

However, turns out it's super complicated in Unity or I'm doing something wrong - hope for the latter :)

My problem is that the current resolutions isn't selected and I also just now found out why. There is a mismatch between the refreshrate in the listed possible resolution and the currentResotution.

 private void SetupResolutionDropDown()
     {
         ResolutionDropDown.ClearOptions();
 
         var resolutionOptions   = new List<TMP_Dropdown.OptionData>();
         for (int i = 0; i < Screen.resolutions.Length; i++)
         {
             var resolutionAsText = $"{Screen.resolutions[i].width}x{Screen.resolutions[i].height} @ {Screen.resolutions[i].refreshRate}Hz";
             resolutionOptions.Add(new TMP_Dropdown.OptionData(resolutionAsText));
             Debug.Log($"Adding Resolution - '{resolutionAsText}'");
         }
         
         ResolutionDropDown.options  = resolutionOptions;
         ResolutionDropDown.onValueChanged.AddListener((index) =>
         {
             _selectedResolutionIndex = index;
         });
 
         RefreshResolutionDropdown();
     }

 private void RefreshResolutionDropdown()
     {
         var currentIndex = GetCurrentResolutionIndex();
         ResolutionDropDown.value = currentIndex;
     }

 private int GetCurrentResolutionIndex()
     {
         for (int i = 0; i < Screen.resolutions.Length; i++)
         {
             if (Screen.resolutions[i].width         == Screen.currentResolution.width && 
                 Screen.resolutions[i].height        == Screen.currentResolution.height &&
                 Screen.resolutions[i].refreshRate   == Screen.currentResolution.refreshRate)
                 return i;
         }
         Debug.LogError($"Unable to find CurrentResolutionIndex for resolution, '{Screen.currentResolution}'");
         return -1;
     }


This works fine in the Unity Editor, but in a build it doesn't. So I looked in the Player.log file to see the above Debug.Logs.

Here I see in the list of possible solutions:

Adding Resolution - '2560x1440 @ 143Hz'

However, the log for the Screen.currentResolution shows me:

Unable to find CurrentResolutionIndex for resolution, '2560 x 1440 @ 144Hz'

So, it's pretty obvious to see why it doesn't find a match, as one have 143Hz and the other have 144Hz.

So, why is that and how can I compensate or am I doing something wrong or?

I know I might be able to just skip the refreshrate from the find logic, however, it will reselect a wrong resolution and I don't want that.

Thanks in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by svgUnityAssets · May 11, 2020 at 08:21 AM

In all fullscreen modes other than "exclusive" the refresh rate will be that of whatever refresh rate your desktop runs. Because as the FullScreenMode enumeration's names imply, anything but "exclusive" is running in a window even if you can't see the window title and borders.

It's only exclusive fullscreen mode that allows setting the refresh rate manually (unless overridden by driver settings).

Hence: try again with FullScreenMode set to ExclusiveFullScreen in Player Settings.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by ozonex · Sep 01, 2020 at 06:37 AM

@Laumania Did you found any solution? I have exactly same issue and Im unable to find how to deal with refresh rates. Everybody ends up with just using FullScreenWindow instead of ExclusiveFullScreen because you don't need to care about refresh rate. But exclusive mode gives more performance and more control so its strange that nobody found a solution.

I also think that it might not be the issue of only Unity itself, because when i enter to supported modes in Windows screen settings i also see this strange behavior.

In Windows for 2560x1440 i have supported refresh rates: 59hz, 60hz, 75hz, 100hz

Selecting 59 and 60 gives the same refresh rate 59hz. Selecting 75hz gives 74hz and 100hz is 99hz.

In unity for that resolution Screen.resolutions gives me 59hz, 74hz and 99hz. So somehow it finds out that all these options will end up and it seems correct apart from these strange values.

But then again when i use any of them in Screen.SetResolution() like that:

 Screen.SetResolution(res.width, res.height, FullScreenMode.ExclusiveFullScreen, res.refreshRate);

Screen.currentResolution returns 60hz, 75hz and 100hz.

I can manually search for pairs like 59hz and 60hz and if not exactly the same is found then try to use other one, but this will be an ugly workaround.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Laumania · Sep 01, 2020 at 06:52 AM 0
Share

Sadly no, I haven't found a solution. However, I must admit I haven't looked more into it since, as I have focused on other stuff in my game. It is something I'll get back to, as it annoys me :D

avatar image ozonex · Sep 01, 2020 at 05:38 PM 0
Share

After whole day I think i managed to get it working using that workaround.

         static bool CompareRefreshRates(int a, int b)
         {
             return GetRoundedRefreshRate(a) == GetRoundedRefreshRate(b);
         }
 
         static int GetRoundedRefreshRate(int refreshRate)
         {
             switch (refreshRate) // Hard coded pairs
             {
                 case 23:
                     return 24;
                 case 29:
                     return 30;
                 case 47:
                     return 48;
                 case 59:
                     return 60;
                 case 75:
                 case 74:
                     return 75;
                 case 164:
                 case 165:
                     return 165;
             }
 
             if (refreshRate > 60) // 100, 120, 144 etc.
             {
                 if (refreshRate % 2 > 0) // Always its rounded to smaller odd number
                 {
                     return refreshRate + 1; 
                 }
             }
 
             return refreshRate;
         }

This is used only when game is in ExclusiveFullScreen mode. I needed to replace "Fullscreen" toogle in the game with switch Window/Borderless/Exclusive.

In window resolution list is blocked and it displays Screen.width and Screen.height.

In Borderless i filter out and hide refreshRate so users can only select widht/height.

Only in Exclusive mode i display all refresh rates. When creating list I marge all similar refresh rates using CompareRefreshRates() and displays it on UI list as one converted by GetRoundedRefreshRate() so it looks correct for users.

To find what resolution is correctly selected i first try to find resolution with same refreshRate. If it fails then it search refreshRate using CompareRefreshRates(). When it also fails then use highest possible. I can imagine many issues with that solution, thats why by default our game starts in Borderless, but Exclusive mode works fine on all of our devices that we tested (PC, laptops, TVs)

avatar image Laumania ozonex · Sep 02, 2020 at 09:35 AM 0
Share

Nice, I'll take a look at this once I get back to it in my game.

However, I know why you did it, but I really don't like this hardcoded adjustment of the refreshrate - but it's also really odd that we get these wierd numbers :S

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

116 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Does Resolution of images used in game affect performance on Low End Devices? 0 Answers

Is it possible to make unity's camera render in chunky pixels? 2 Answers

multiple apks to match certain devices 0 Answers

2D Gameobject Location and scaling in different screen size(mobile) 0 Answers

2D Gameobject size not scale as per sreen-resolutin.,I trying to make jumping ball blast game. and i have all most done in 1080*1980 resolution. 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges