So, I’ve been following a tutorial for procedural dungeon generation, and even though on compile the scripts work just fine, when I run the game I sometimes get this compiler error
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
which is really weird, I would expect to get an error every time I run, although either way nothing happens, no dungeon generates even though it seems like it should work fine, and the even weirder part is the error message keeps telling me the error is happening on the linereturn corridor; which is super strange since that line has nothing to do with an index. although I do return it to HashSet<Vector2Int> corridors = ConnectRooms(roomCenters); so, maybe that’s where the error is coming from, although this statement of code works in the tutorial so I don’t see why it’s not working here, I have no idea what’s going wrong though, could someone help?
What does the callstack look like on the error when it happens? (in the lower part of the console when you select that error)
Not if your code changes based on random numbers, as most procgen code does.
Either way, this always applies:
Here are some notes on IndexOutOfRangeException and ArgumentOutOfRangeException:
Steps:
- find which collection it is (critical first step!)
- find out why it has fewer items than you expect
- remember you might have more than one instance of this script in your scene/prefab
Thanks