- Home /
Can I force game execution to stop in the editor?
Hi
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.
Thanks
Answer by qJake · Sep 05, 2010 at 08:49 PM
Use Debug.Break();
http://unity3d.com/support/documentation/ScriptReference/Debug.Break.html
Ctrl+Shift+P also does the same thing (pauses).
This actually stopped an infinite loop? Debug.Break is only supposed to stop at the end of the current frame. A loop implies it never gets there.
Yes, but how do we abort game execution in Play mode (play button has been pressed) without having to force-quit Unity (and potentially lose work). Ctrl+shift+p doesn't do that for me on my $$anonymous$$ac.
The docs for Debug.Break() says that it PAUSES tje editor. Is there a way in a script to completely STOP The playmode? As if the uset had press the blue play button on the editor and it turns black?
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#endif
Answer by Venryx · Oct 15, 2016 at 06:30 AM
You can attach the debugger from MonoDevelop or Visual Studio, then change the variables and such to make the loop break.
For infinite loop problems try this: https://blogs.unity3d.com/2016/05/24/breakout-how-to-stop-an-infinite-loop-in-a-unity-c-script/
There are also plugin solutions out there like this: https://www.assetstore.unity3d.com/en/#!/content/40167
Answer by DDaddySupreme · Jul 15, 2017 at 09:00 AM
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.
Your answer

Follow this Question
Related Questions
force quitting 2 Answers
Admob Plugin - Android Manifest Problem 1 Answer
Linux build freezes on application.quit 0 Answers
Unity freezes on Quit (4.3) 2 Answers
Unity keeps force quitting on Mac no matter how small my action is? 1 Answer