- Home /
Remove specific screen resolutions
Hey guys. I am trying to remove some resolutions in my dropdown menu. I want to remove because I will not use it. This what I did (see code below) but I got this error: ArgumentOutOfRangeException: Argument is out of range. Parameter name: index System.Collections.Generic.List
1[TMPro.TMP_Dropdown+OptionData].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633) SettingsManager.OnEnable () (at Assets/Scripts/Settings/SettingsManager.cs:38)`
What I've tried:
resolutions = Screen.resolutions;
foreach (Resolution resolution in resolutions) {
for(int i = 0; i < resolutions.Length; i++) {
if(resolutionDropdown.options[i].text == "320 x 200") {
resolutionDropdown.options.RemoveAt (i);
break;
}
}
resolutionDropdown.options.Add(new TMPro.TMP_Dropdown.OptionData(ResolutionToString(resolution)));
}
That's because you are iterating resolutionDropdown.options and removing from it in one loop, also you are adding to dropdown at the end, so in first iteration there are no values, so this "for" will throw exceptions because resolutions.length is not same as resolutionDropdown.options length. Also try to refactor this function, because this "for" in "foreach" looks a little bit unclear. I think you can just add "if" before adding to dropdownlist in this first foreach. Like:
foreach (Resolution resolution in resolutions)
{
if (resolution.width != 320 && resolution.height != 200)
{
resolutionDropdown.options.Add(new T$$anonymous$$Pro.T$$anonymous$$P_Dropdown.OptionData(ResolutionToString(resolution)));
}
}