Hello, I have followed the Hack and Slash tutorials by BurgZergArcade successfully up to number 30 (Or half way through it at least). At 4:34 on the video, when i try to save the vitals, unity says that I have a StackOverflowException. I am pretty sure from Google searches that this means I have an infinite loop of some kind, but I can't find where it is in my code and I can't find anyone else who has had the same problem. I am quite new to using CSharp in Unity and I was hoping that the tutorials would help me to improve, so it would be a great hep to me if someone could help me out. This is my code for saving the vitals:
This piece of code can't cause a stackoverflow. Maybe your GetVital function is causing it. Are you even sure that this is causing it? Have you tried to comment out this part?
Infinite loops just freeze your application. The most common reason for a stack overflow is an end recursion. In other words a function is calling itself without a reasonable break-condition. This can be directly or indirectly.
Each function call will push the return address on the stack and create the local stack frame for the function. When the function exits this is cleaned up, but you never leave the function so the stack grow until you run out of stack memory.
answered Apr 29 '12 at 02:23 PM