Can I force game execution to stop in the editor?


Supposing I have a bug which caused an infinite loop (or any other lock-up), is there a way (while in the editor) to force-stop the game running? Maybe a key combo or such like?

I ask because this just happened to me and I had to force quit Unity and lost 15 minutes work.


Use `Debug.Break();`

Ctrl+Shift+P also does the same thing (pauses).

You can attach the debugger from MonoDevelop or Visual Studio, then change the variables and such to make the loop break.

What I do is I implement a count int (set to 0) before every while loop. At the end of the loop add one to it, and somewhere else add an if statement that uses Debug.Break() and Debug.LogError(“”) if count gets above 100, or any other number that it should never get to. This way you can also leave an error message to see what happened.

Not quite an answer to the question, but it’s a good preventative measure.