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.
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.