ArgumentOutOfRange Exception with dropdowns
Hi guys,
I have been trying to solve an issue all night. I am trying to get to dropdowns to populate with items. Currently only one works even though they share near identical code.
Error: ArgumentOutOfRangeException: Argument is out of range. Parameter name: index.
I removed most irrelevant code, hopefully someone can help because i am ripping my hair out over here. The resolutionsDropdown is the one with the issues. the other dropdown works flawlessly.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using UnityEngine.Audio;
public class mainMenuOptions : MonoBehaviour {
private string[] qualityNames;
private Resolution[] resolutions;
public Dropdown qualityDropdown;
public Dropdown resolutionsDropdown;
public Toggle fullScreenToggle;
public Toggle vSynchToggle;
public AudioMixer mixer;
public Toggle subtitleToggle;
public Slider masterVolSlider;
public Slider musicVolSlider;
public Slider sfxVolSlider;
public Slider dialogueVolSlider;
// Use this for initialization
void Start()
{
qualityNames = QualitySettings.names;
resolutions = Screen.resolutions;
for (int i = 0; i < qualityNames.Length; i++)
{
qualityDropdown.options[i].text = qualityNames[i].ToString();
}
for (int i = 0; i<resolutions.Length; i++)
{
resolutionsDropdown.options[i].text = (resolutions[i].width.ToString() + " x " + resolutions[i].height.ToString());
}
qualityDropdown.value = QualitySettings.GetQualityLevel();
}
//Snip
}
make sure the arrays you're indexing with i are of the exact same length, or implement a check what should happen if not.
Your answer
Follow this Question
Related Questions
Make static object height match the max height of a bouncing ball in any resolution 0 Answers
Some question about making Android game. 0 Answers
Unity .exe resolution problem on Windows 10 (with TV as Screen) 1 Answer
Vertical resolution of Kinect-v2 in Unity 3D 0 Answers
QualitySettings.resolutionScalingFixedDPIFactor is not working realtime 0 Answers