I think it would be better to avoid an infinite loop as it is likely to make most IDE's hang (at least temporarily).
Answer by boymeetsrobot
Answer by duck
Short answer - unfortunately, no - if you have already got Unity frozen in an infinite loop, your only option is to force-quit.
However, this question makes me wonder why you're putting an infinite loop in there on purpose in the first place. What are you using it for?
In general, in Unity, you would use the Update() and FixedUpdate() functions for "game loop" type code, because these functions get called every frame, and every physics step respectively, whilst releasing control to Unity's other systems (rendering, physics, etc) between steps so as to not lock up the entire thread. Eg, to some action every frame:
function Update() {
// increment a variable 'i' by 1 each frame:
i++;
}
Another method of creating a non-hanging loop is to use a Coroutine, which is a type of function which allows you to explicitly specify certain points where the execution should be paused and control released to other processes until a certain time.
An example of a "non hanging" loop in a coroutine, in Unity's Javascript:
function MyLoop() {
while (true) {
print("hello world!);
yield;
}
}
And in C#:
IEnumerator MyLoop () {
while (true) {
Debug.Log("hello world!);
yield return null;
}
}
Hope this is helpful.
Answer by Proclyon
With all due respect, you should not even be trying to do such a thing with the engine, but with the code. I know it's really annoying when somebody won't answer your question. But I'm just trying to share my experience on this, and the answer I can give you is , don't get an infinite loop, EVER!
The reason is simply because it doesn't get out, and why should anything else then the code be responsible? It shouldn't, the code is. Otherwise it's going to get really confusing when the responsibility starts shifting to places where they don't belong.
Answer by banreaxe
Answer by CB-TV
Answer by JaredThomson
Answer by LeetRooster
Answer by FamerJoe
Answer by MvD
Answer by Stephanie The Viking
Answer by TJS
Answer by Will H
Answer by GilesDMiddleton
Answer by boymeetsrobot
I think it would be better to avoid an infinite loop as it is likely to make most IDE's hang (at least temporarily).
Answer by duck
Short answer - unfortunately, no - if you have already got Unity frozen in an infinite loop, your only option is to force-quit.
However, this question makes me wonder why you're putting an infinite loop in there on purpose in the first place. What are you using it for?
In general, in Unity, you would use the Update() and FixedUpdate() functions for "game loop" type code, because these functions get called every frame, and every physics step respectively, whilst releasing control to Unity's other systems (rendering, physics, etc) between steps so as to not lock up the entire thread. Eg, to some action every frame:
function Update() {
// increment a variable 'i' by 1 each frame:
i++;
}
Another method of creating a non-hanging loop is to use a Coroutine, which is a type of function which allows you to explicitly specify certain points where the execution should be paused and control released to other processes until a certain time.
An example of a "non hanging" loop in a coroutine, in Unity's Javascript:
function MyLoop() {
while (true) {
print("hello world!);
yield;
}
}
And in C#:
IEnumerator MyLoop () {
while (true) {
Debug.Log("hello world!);
yield return null;
}
}
Hope this is helpful.
Answer by Proclyon
With all due respect, you should not even be trying to do such a thing with the engine, but with the code. I know it's really annoying when somebody won't answer your question. But I'm just trying to share my experience on this, and the answer I can give you is , don't get an infinite loop, EVER!
The reason is simply because it doesn't get out, and why should anything else then the code be responsible? It shouldn't, the code is. Otherwise it's going to get really confusing when the responsibility starts shifting to places where they don't belong.