IndexOutOfRangeException

Hey, I’ve run into this weird bug: When one of the units tries to cross from 5th grid to 6th, game stops and this error pops up.

It happens both on x and y axis as if there wasn’t the 7th element in the array. I create the grid in LevelGrid:

2 Likes

What are you doing on GridSystem.cs:63 ? Looks like perhaps it’s returning null when trying to get a GridObject, add a Debug.Log(); to see what X and Z you are using and where exactly is it failing.
Either you’re not creating the Grid with the full 10,10 size; Or you are creating but for some reason you stop creating GridObjects after 7

Or perhaps the issue is on the Move Action validation, did you forget to first test if the testGridPosition is valid? Perhaps as you approach the right side you forgot to check that the testGridPosition is under width/height so when testing the MoveAction range you’re testing outside the Grid.

4 Likes

Okay, so I’ve found my mistake. On ‘IsValidGridPosition’ I was checking ’ <= ’ width and height instead of ’ < '… Thx for helping with this :smiley:

2 Likes

I literally ran into the same issue. Was ready to jump on here and point it out in case others did too.
Looks like you beat me to it!

Privacy & Terms