Quantcast
Channel: Answers for "Can the Unity editor break out of an infinite loop in a script?"
Viewing all articles
Browse latest Browse all 39

Answer by JaredThomson

$
0
0
I know it's an old question but I do have a better solution. As others have said: don't use an infinite loop by design. However if you did it by mistake and don't want to loose a whole scene or other unsaved data here's what you can do: ---------- 1) Open mono develop and attach it to the editor if you haven't already.(Run > Attach To Process) 2) Pause execution from mono develop.(Run > Pause) 3) Go to your immediate window (View > Debug Windows, if you don't see it at the bottom). 4) Modify the value that's causing you to loop infinitely. The Immediate window lets you just type in some code that will execute in that scope. ---------- For me, the problem was looping over a list and trying to find a specific value that matched an element. I didn't properly handle the value not existing so it looped infinitely. All I had to do was call listname.Clear(); in the immediate window and the loop broke out on the next iteration. If you were doing something exceptionally silly like while(true){ /* some silly code */ } you might be able to break out by just calling return. If you were calling that function every frame you might have to be a bit more sneaky and call T.Destroy(gameObject.GetComponent()) or something to that effect to remove the script that's calling that silly function. I hope this helps someone else who doesn't want to nuke their work in progress! Cheers.

Viewing all articles
Browse latest Browse all 39

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>