- Home /
Can I use Invoke to protect from an endless loop I am debugging?
Every now and then I will get Unity stuck in a loop, and have to end task and reload everything. It occurred to me just now that I could use Invoke to exit a potential loop after a few seconds, when debugging a squirrely area of code. Will this tactic protect me, generally, or can I hang it so bad it can't think straight? Is it a bad habit? (Should I be doing something else, such as learning more about try/catch, perhaps? - do they represent all the safety I need?)
Answer by facejets · Mar 05, 2021 at 10:46 PM
Maybe it isn't hanging/crashing at all -
(answering my own question, because I may have figured it out)
Are you using a debugger? If the unity editor is playing, and I have attached my debugger, then Unity does not respond. I simply need to go to my debugger (I'm using Visual Studio) and press the red "stop" square before I can stop the editor.