Imagine you're working on your latest app store hit, or in my case a demo game for training purposes. You've made loads of changes and not saved them in Unity yet (oops!). Then you make a script where you forget to put your incrementer in (double oops!).
So off you go, back to Unity, and click play and... NOOOO! It's the spinning beach ball of death... So how do you get out of it?
Well you could click out of Unity, but that would mean losing all those unsaved changes you've made. So what’s another way of exiting the loop?
Here’s How To Exit An Infinite Loop in Unity Using Mono Develop –
First thing, attach the code in mono develop to the running process (by going to run - attach to process, within mono develop)
Then go and find the running instance of Unity that has the problem and attach (down in the bottom right).
This gives you a slightly different window in mono develop.
First click on the pause button at the top of mono develop, to pause execution. This will show you the line that’s running.
Now find the line where the condition is problematic. Then pop a break point on the line that’s causing you problems (& you wish you’d never written).
Now you can hover and select the incrementer and set a value that will make the loop exit. (Don't forget to hit return).
So I have a break point, and I've forced a set value – then when I hit play (continue execution) it’s come out of the infinite loop (yay - big sigh of relief). So you can now save your project, without losing your earlier changes.
Hope this has helped, if you’re interested in finding out more about using Unity to develop games, then join over 25,000 students who felt the same way. Head over to https://www.completeunitydeveloper.com/ for the best price on our course.
Did this work for you?