- Home /
 
How to set screen resolution
I'm trying to lock the screen resolution of a game I'm working on right now without success. From what I was able to find the typical way to do it is either through Screen.SetResolution or via the Player Settings under the project tab.
However when I try to set the screen resolution with code the game doesn't actually update the size but rather leaves it as is. When I try to go to Player Settings, the options for settings screen size are not there as shown in documentation pictures.
Answer by Propagant · Jan 15, 2018 at 05:54 AM
So essentially you want to keep the screen resolution static? Then it'd be great to use PlayerPrefs to store the resolution you want to keep. For example:
 public int LockResX = 1024;
 public in LockResY = 768;
 public bool Windowed = true;
 
 public bool SaveResolution = true;
 void Start()
 {
      if(SaveResolution)
      {
          PlayerPrefs.SetInt("ResX",LockResX);
          PlayerPrefs.SetInt("ResY",LockResY);
          Debug.Log("Resolution has been saved");
      }
      else if(PlayerPrefs.GetInt("ResX")!=null && PlayerPrefs.GetInt("ResY")!=null)
      {
       Screen.SetResolution(PlayerPrefs.GetInt("ResX"),PlayerPrefs.GetInt("ResY"),Windowed);
        Debug.Log("Resolution has been loaded");
      }
      else
         Debug.Log("There is no resolution saved");
 
 }
 
               Basically I've made a 2 registry keys for PlayerPrefs as integers that store the resolution X and Y. If you enable SaveResolution the resolution LockResX and LockResY will be saved to the playerprefs after start. You can also enable/disable windowed mode [which is not saved and loaded after start]. Hope that helps.
Thanks for the code but that's not quite what I'm looking for. Right now I'm in full screen mode but I want to lock the resolution to a value I choose. The problem I'm having with it is that Screen.SetResolution isn't actually setting the resolution of the game. When I check the resolution after the game has started, it reports back whatever the size of my monitor is rather than the scale I've provided.
Your answer