This line of code is crashing Unity

Edit: I figured it out. I had an endless loop, which was triggered when the length of the array was more than 1.

I can’t enter play mode because of this line of code:
wrongAnswersTMP = new TextMeshPro[wrongAnswersGO.Length];

It’s likely that there’s nothing wrong with that line, but that there’s something wrong with the way you’re using that variable later on in your code, and if the variable isn’t initialized then the bad code doesn’t run (or runs differently).

Editor freezing in play mode probably means you have an infinite loop.

1 Like

Doesnt an infinite loop cause a stack overflow and stop play mode? I dont really have those a lot but IIRC that exists.

An infinite loop (in the main thread) will cause a freeze as Antistone notes.

while (true)
{
    a++;
}

Infinite recursion will cause a stack overflow.

public bool A()
{
    return !A();
}
1 Like