#ArgumentOutOfRangeException

1 messages · Page 1 of 1 (latest)

fleet minnow
#

I have a list of type gameobject, that stores the arrows that are fired towards outside the trigger zone. I wanted to make it so if there are more than 4 arrows fired, the game would start destroying the first one in the list every time after a fire from that point to not potentially butcher the performance. Then move every gameobject in the list one index up, and finally remove the last slot in the list. The problem comes up with the error message and idk how to fix it.

fleet minnow
#

If it helps, I get this error the moment the 5th arrow leaves the trigger

rocky notch
#
  1. IndexOf is slow. Why not use a for loop and save you that?
  2. Always doing - 1 on the index means that you might end up with 0 - 1, which will be out of range and likely cause the error you are experiencing.