- Home /
Question by
lothlorientos · Jul 13, 2014 at 02:55 PM ·
bug-perhapsarray-out-of-range-exceptindexing-array
IndexOutOfRangeException: Array index is out of range.
I have this array:
public GameObject[] arrayname= new GameObject[4];
and this code for this array:
if (arrayname[0]!= null)
{
if (arrayname[1]!= null)
{
if (arrayname[2]!= null)
{
if (arrayname[3]!= null) //HERE IT POPS THE ERROR!!!!!!!!!!!!!!!!!!
{
arrayname[3].SetActive (false);
arrayname[3]=arrayname[2];
arrayname[2]=arrayname[1];
arrayname[1]=arrayname[0];
arrayname[0]=otherarray [i];
}
else
{
arrayname[3]=arrayname[2];
arrayname[2]=arrayname[1];
arrayname[1]=arrayname[0];
arrayname[0]=otherarray [i];
}
}
else
{
arrayname[2]=arrayname[1];
arrayname[1]=arrayname[0];
arrayname[0]=otherarray [i];
}
}
else
{
arrayname[1]=arrayname[0];
arrayname[0]=otherarray [i];
}
}
else
{
arrayname[0] = otherarray [i];
}
Is this some kind of bug? Because I didn't go out of range.
Comment
Best Answer
Answer by YoungDeveloper · Jul 13, 2014 at 02:56 PM
Your array is public so it will be overwritten from inspector, are you sure that array size in inspector is 4 ?
public GameObject[] arrayname;
Yep that was the problem,I just found out too. haha Thanks ;)
Your answer
Follow this Question
Related Questions
Mesh.colors is out of bounds 0 Answers
Array index is out of range 1 Answer
OnTriggerEnter only sent to one of the colliding objects, not both? 0 Answers
Screen.SetResolution causes screen to turn black (and other problems). Am I doing it right ? 1 Answer
Is it a problem or bug about reflection probes which causes glitch? 0 Answers