How to make the unity editor respond while a script is working?
Hello, when i have a heavy script it hangs up the whole unity editor.
Lets say i just write while(True) in a script then i start the script and the editor will never respond again i cannot just stop the script how can i make sure this does not happen?
I would like a way to do this from the editor side i like to avoid to create constructions in the script that make it more complex or less compatible.
Answer by Xarbrough · May 29, 2016 at 08:27 PM
This is not a trivial thing to do, but recently there was a blog post about it: Unity Blog
Other than that there is no real way to stop an infinite loop other than quitting Unity or quitting the Unity process via the *Task Manage*r or similar.
You should be saving your scene every time before you hit play anyway. Also I don't think that infinite loops are a common problem. It's only annoying if it happens and you forgot to save.
Hmm i see it essentially generates an exception. I think its really usefull if i really forgot to save (which happened but rarely)
But my question is more about how to keep the interface responsive in a loop or more common in a script that takes a time to execute its just very irritating when its getting stuck on start of a program. However the blog entry might still be useful some day.
You simply can't. Your code and the editor run on the same thread. If one takes too much time, both will get stuck. But that really shouldn't be big problem, if you avoid mistakes and save often.
Answer by ninja_gear · May 30, 2016 at 03:16 AM
You can limit a while loop with a Sentinel variable:
var tries = 100;
while (true || tries-- > 0)
{
//loop here
}
Your answer
Follow this Question
Related Questions
Basic Code Problem 1 Answer
Loading a scene with script loads multiple copies of another scene, the crashes Unity 0 Answers
Glitch Effect On Text 0 Answers
,Attack and chase range issue 2 Answers