* Break out of any infinite loop on the main thread (Including Editor and Play mode)
* Customizable emergency exit keyboard codes (default CTRL + F10)
* Check if the Emergency Exit thread is alive (default CTRL + F9)
* Once EE is triggered, play mode is paused. From here you can either stop playmode entirely OR resume playmode without any troubles.
All you need to do is add the EmergencyExit component to any gameobject.
* ONLY on .NET 4.x which should be in Unity versions 2017 to current (2021), but check yourself to make sure.
* ONLY on Windows (but only because I dont know how to get keyboard Input on mac or linux which bypasses unitys input system. If you can help here, please contact me email@example.com).
This tool helps you break out of infinite loops. this tool does not modify your existing code in any way, like previous methods, so the excecution speed of your programm and assembly is exactly the same with and without this tool. this works for any infinite loop which is on the main thread, so most things in unity. it works both inside the editor and in play mode. the emergency exit can be trigger via a key combination (default is CTRL + F10, but can be changed inside the code easily to anything you want). in order to get emergency exit to work, you need to add the EmergencyThread script to any Gameobject, which will then start a new thread that lingers in the background an listens to the keyboard for the Emergency Exit Code. it will poll the keyboard state about 5 times a second, so performance will not be impacted in any way. once the thread sees the Exit Code, it will thow an exception into the main thread and set the editor into pause mode. You can even resume play from here to get back into action without having to exit playmode!
the method i am using to throw an exception into the main thread only works in .NET 4.x which unity uses from about version 2017 to current (2021), But unity is working towards .NET 5.x, at which point this method will not work anymore. Its best to check yourself if your project currently uses .NET 4.x!
ONLY WINDOWS IS SUPPORTED, but this is only because i dont know how to get keyboard input on other systems. If you can help me get keyboard input on non windows systems, send me an email: firstname.lastname@example.org. Important here is, that you cannot use the unity Input system, because that will lock up when an infinite loop is encountered.
This tool throws an exception into the main thread. if the main thread is currently not stuck in an infinite loop, but somewhere else deep withing unity internals and you call the Emergency Exit, then that may cause problems.