I create this for loop, but for some reason it gives the error "A StackOverFlowException has occurred". I really don't know anything about this error, nor do I know how to produce it.
I really hope there are some talented people out there who can help me.
asked Jan 03 '12 at 05:48 PM
This usually means that you have an unbounded recursion, that is, a function is calling itself over and over, until the call stack is full. (see more)
The piece of code you posted doesn't show, but I'm guessing that it's inside a function that is being called by ApplyDamage (or inside ApplyDamage itself) and colliders refers to the same objects on different instances of this script.
Eg.: there are 2 instances of this scripts in gameobjects A and B. In A, colliders has only the collider from B, and in B colliders there's the collider from A. If I'm guessing right, when ApplyDamage is called for A, it will call ApllyDamage from B, and than it will call ApplyDamage from A, and so on causing an Stack overflow.
One way to stop the recursion is using flags that prevent the same function to be called multiple times on an instace of your script.
answered Jan 03 '12 at 06:28 PM