I created a script that used to check all number at mesh.triangles
and save the value if we did not save it yet to array variable that i created manually in script , but before the script even go check , it's stuck at comparing normal variable with array variable , but why ? because we can't compare normal variable with array variable or what ? here is my script :
Mesh secondmesh = GetComponent<MeshFilter> ().mesh;
Vector3[] secondvertices = secondmesh.vertices;
int[] secondtriangle = secondmesh.triangles;
int saverone = one;
int savertwo = two;
int saverthree = three;
int[] saveint = new int[secondtriangle.Length];
Vector3[] savevector = secondvertices;
// check for number that available in triangle
for (int anythingtwo = 1; anythingtwo < ( secondvertices.Length + 1 ) ; anythingtwo++)
{
saveint [0] = 0;
int idontknowthistriangle = secondmesh.triangles [anythingtwo];
bool isalreadyavailableinsaveint = false;
// check if the same number already exist in the array
for(int anythingthree = 0; anythingthree < ( saveint.Length + 1)
&& anythingthree < ( secondtriangle.Length + 1) ;anythingthree++)
{
// the error is at line below this comment and another line
// that is in the bottom of the script
if (idontknowthistriangle == saveint [anythingthree])
{
Debug.Log (" | anything three , already found ! |");
isalreadyavailableinsaveint = true;
break;
}
}
// if the same number is found in the array
if (isalreadyavailableinsaveint == true)
{
Debug.Log (" | already available in save int ! | ");
}
// if the array does not contain same number
if (isalreadyavailableinsaveint == false)
{
// count how many times the search found that the array
// don't contain the value we found
totalcount++;
Debug.Log (" | total count : " + totalcount + " | ");
// error also here !
saveint [anythingtwo] = idontknowthistriangle;
}
}
This is the error immediately :
// the variable used at the error
int[] secondtriangle = secondmesh.triangles;
int[] saveint = new int[secondtriangle.Length];
int idontknowthistriangle = secondmesh.triangles [anythingtwo];
// the error is located at
if (isalreadyavailableinsaveint == true) {
// and
saveint [anythingtwo] = idontknowthistriangle;
The error is located using the comment at the script , but i don't get it why , can anyone tell me why is this happening ? because what i though int
never be null
and i can even debug log the variable ( output 0 ) no matter i set it or not .
anythingtwo
is not related to thesaveint
array in any way and you don't check its bounds. Andanythingthree < ( saveint.Length + 1)
is already defined to go out of bounds – UnholySheep Mar 14 at 8:35null reference exception
, but the grammar is much to be desired, and I am worried any further edits may deviate from your intent. – Gnemlock Mar 14 at 8:50IndexOutOfRangeException
(which would be consistent with my analysis of the code) - not sure why OP assumes that there arenull
values in the arrays – UnholySheep Mar 14 at 8:52