Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Cryno1000 · Aug 21, 2021 at 05:49 PM · screenaspect-ratioscreen resolutionaspect ratioplayer settings

Screen.SetResolution not behaving as expected

Hey, I've been having an issue that has been making me feel insane for a couple of days now. I've looked everywhere but nothing seems to work.

Whenever I use Screen.SetResolution(), the aspect ratio doesn't change correctly. When I start the game, the highest resolution my monitor supports is applied and looks correct. But, whenever I change my resolution, the aspect ratio (no matter what resolution I choose) gets set to something like 4:3 or 5:4. Obviously, I want the aspect ratio to reflect what the resolution's aspect ratio is. I've attached scripts from my resolution dropdown and my display manager (a script so I can change resolution, fullscreen, etc. from anywhere) and screenshots of my player settings and what the window looks like after I change the resolution.

Resolution Dropdown:

     Resolution[] resolutions;
     Dropdown resolutionDropdown;
 
     public void Start()
     {
         resolutionDropdown = GetComponent<Dropdown>();
         resolutions = Screen.resolutions;
         resolutionDropdown.ClearOptions();
         List<string> options = new List<string>();
 
         int currentResolutionIndex = 0;
         for (int i = 0; i < resolutions.Length; i++)
         {
             //I didn't want multiple of the same resolution just with different refresh rates appearing, so I added this check to make sure there aren't duplicates.
             if (i > 0 && resolutions[i].width == resolutions[i - 1].width && resolutions[i].height == resolutions[i - 1].height) { }
             else
             {
                 string option = resolutions[i].width + " x " + resolutions[i].height;
                 options.Add(option);
                 if (resolutions[i].width == Screen.width && resolutions[i].height == Screen.height) currentResolutionIndex = i;
             }
         }
         resolutionDropdown.AddOptions(options);
         resolutionDropdown.value = currentResolutionIndex;
         resolutionDropdown.RefreshShownValue();
     }
 
     //This is called when a player selects a resolution from the dropdown
     public void SetResolution(int resolutionIndex)
     {
         //Since I change the value in Start (when showing all the options), I need to add this check so it doesn't automatically change. 
         //If you have another way of doing this that is better, please let me know.
         if (Time.timeSinceLevelLoad > 0.1f)
         {
             Resolution resolution = resolutions[resolutionIndex];
 
             PlayerPrefs.SetInt("resolutionX", resolution.width);
             PlayerPrefs.SetInt("resolutionY", resolution.height);
             PlayerPrefs.Save();
 
             DisplayManager.instance.AdjustResolution();
         }
     }

DisplayManger:

 public static DisplayManager instance;

 void Start()
 {
     instance = this;
 }

 public void AdjustResolution()
 {
     bool fullscreen = false;

     if (PlayerPrefs.GetInt("fullscreen") == 1) fullscreen = true;
     else fullscreen = false;

     Screen.SetResolution(PlayerPrefs.GetInt("resolutionX"), PlayerPrefs.GetInt("resolutionY"), fullscreen);

     //This prints out the correct resolution that I just selected.
     Debug.Log("Resolution: " + PlayerPrefs.GetInt("resolutionX") + " x " + PlayerPrefs.GetInt("resolutionY") + ". Fullscreen: " + fullscreen);
 }

Player settings. I've tried changing the fullscreen mode but that doesn't seem to work either. alt text

Then here is what the game looks like when I am running it. It is supposed to be 1920 x 1080. I should mention that my monitor is 3440 x 1440, but even selecting 3440 x 1440 produces a similar result. alt text

Any ideas about what may be causing this and how I could fix it?

player-settings.jpg (48.7 kB)
resolution-error.jpg (179.0 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

124 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Aspect Ratio ( supporting different screen resolutions ) 1 Answer

size of window 0 Answers

Clamping after forcing aspect ratio 0 Answers

Scale Everything In Game to Fit all screen Sizes 1 Answer

Trouble with cutting out background in builds 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