"IndexOutOfRangeException" on 2D GameObject array

private GameObject[,] buildEndRoad = new GameObject[999,999];

so I’m trying to place a road in [17,53] on this

buildEndRoad[xM,zM] = (GameObject)Instantiate(sRoadSTR,new Vector3((xMroadDist)+20,startH,zMroadDist+0),Quaternion.Euler(0,0,0));

I get “IndexOutOfRangeException”

Debug it to:

  • Ensure that buildEndRoad really is 999 by 999 elements.
  • Ensure that xM and zM really are 17 and 53 so you did not mistake them for any other variable.

Tip: If you don’t want to attach the debugger for any reason, you can use buildEndRoad.GetLength(0) and buildEndRoad.GetLength(1) to get the x and y dimensions, then just print it out.

If you still can’t figure it out, I think you need to give us a little bigger snippet of code.