Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
1
Question by Gooball60 · Feb 03, 2018 at 04:30 AM · resolutions

[Solved] Screen.resolutions returning duplicates

In the editor, Screen.resolutions functions as expected. The problem is on standalone where it appears to duplicate each resolution with refresh rates of 60Hz and 48Hz. Is there any way to only use 60Hz refresh rates or completely omit refresh rates when getting Screen.resolutions?

This is the Screen.resolutions log when cycling through resolutions: 1920 x 1080 @ 60Hz 1920 x 1080 @ 48Hz 1680 x 1050 @ 60Hz 1680 x 1050 @ 48Hz 1600 x 900 @ 60Hz 1600 x 900 @ 48Hz And so on...

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
8
Best Answer

Answer by FlaSh-G · Feb 03, 2018 at 05:52 PM

You can filter out all non-60hz results after calling the function.

A Linq statement like this would work:

 var resolutions = Screen.resolutions.Where(resolution => resolution.refreshRate == 60);

Either way - remember that the hz number is not unimportant. Especially for people using monitors that go above 60hz.

Also: You might have different results on different computers. My test just gave me a lot of resolutions, but none of them were 60hz. So if you want to just have unique height and width results, filter for that.

 var resolutions = Screen.resolutions.Select(resolution => new Resolution { width = resolution.width, height = resolution.height }).Distinct();

Be aware that this statement will delete the hz info completely.

Remember to use

 using System.Linq;
Comment
Add comment · Show 5 · 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 Gooball60 · Feb 03, 2018 at 08:31 PM 1
Share

When I try to use that function with an array I get this error: error CS0266: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<UnityEngine.Resolution>' to 'UnityEngine.Resolution[]'. An explicit conversion exists (are you missing a cast?)

$$anonymous$$y resolution system relies on the array of resolutions that Screen.resolutions puts out. Any idea how I could incorporate said Linq function into that system?

avatar image FlaSh-G · Feb 04, 2018 at 01:19 AM 1
Share

Put this

 .ToArray()

afterwards to make an array out of it.

avatar image Gooball60 FlaSh-G · Feb 04, 2018 at 01:55 AM 0
Share

Well that solution was simpler than what I was expecting. Anyway, everything is working as intended now, thank you for the help!

avatar image FZ_Applications · Mar 30, 2020 at 03:38 PM 1
Share

Using this in 2020 this is a bad idea. Screens with refresh rates over 60Hz are beco$$anonymous$$g mainstream.

avatar image SwingWren FZ_Applications · Jun 01, 2020 at 03:08 PM 1
Share

$$anonymous$$aybe it may not be a bad idea as SetResolution will use the highest refresh rate supported by the monitor by default but yes the user loses the option to choose a specific refresh rate. The best option would be to have a drop-down showing the resolution without the refresh rate and another drop-down to choose the refresh rate.

avatar image
3

Answer by FZ_Applications · Mar 30, 2020 at 04:27 PM

More and more high refresh rate monitors are being used. Keeping the player stuck at 60Hz is not good. This method filters out low refresh rates.

 public static List<Resolution> GetResolutions() {
     //Filters out all resolutions with low refresh rate:

     Resolution[] resolutions = Screen.resolutions;
     HashSet<Tuple<int, int>> uniqResolutions = new HashSet<Tuple<int, int>>();
     Dictionary<Tuple<int, int>, int> maxRefreshRates = new Dictionary<Tuple<int, int>, int>();

     for (int i = 0; i < resolutions.GetLength(0); i++) {
         //Add resolutions (if they are not already contained)
         Tuple<int, int> resolution = new Tuple<int, int>(resolutions[i].width, resolutions[i].height);
         uniqResolutions.Add(resolution);

         //Get highest framerate:
         if (!maxRefreshRates.ContainsKey(resolution)) {
             maxRefreshRates.Add(resolution, resolutions[i].refreshRate);
         } else {
             maxRefreshRates[resolution] = resolutions[i].refreshRate;
         }
     }

     //Build resolution list:
     List<Resolution> uniqResolutionsList = new List<Resolution>(uniqResolutions.Count);
     foreach (Tuple<int, int> resolution in uniqResolutions) {
         Resolution newResolution = new Resolution();
         newResolution.width = resolution.Item1;
         newResolution.height = resolution.Item2;
         if(maxRefreshRates.TryGetValue(resolution, out int refreshRate)) {
             newResolution.refreshRate = refreshRate;
         }
         uniqResolutionsList.Add(newResolution);
     }

     return uniqResolutionsList;
 }
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

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.

Follow this Question

Answers Answers and Comments

77 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

Related Questions

Remove 800x500 From Build Configuration 0 Answers

Ideal resolutions for 2D platformer Art Assets (to make multi-res support easier)? 2 Answers

Is there any way to change Preview resolution by code? 2 Answers

After upgrading to 2018.2.6f1 full screen resolution is wrong 1 Answer

UGUI Aspect Ratios and Resolutions 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges