If Key Pressed, Toggle loop

Im trying to detect if a key has been pressed. If its been pressed repeat loop until its not pressed.

Every time I figure something out the editor crashes from what I assume is an infinite loop (Which I guess is kind of what I need).

How can I fix this?

If you are going to loop during the same tick until the key is released, it never gets a chance to check for the button being released because the loop will go as many times as possible before the next tick where it would check for the button release.

So instead of looping just do it once per timer event or per tick unless the button has been released which you can check on by setting a boolean variable on the press and release events. If you need to cycle through an array over time, keep track of the array index with a separate Integer varisble and increment it once per timer event or tick

This will make it act like a loop but happen over time i stead of all at once.

As @mightyenigma said - use tick to execute what you want.

Create some boolean, and change it to true/false when key pressed/unpressed.

In Tick add simple Branch(if) with that boolean and execute desired functionality in it.

Im trying to detect if a key has been
pressed. If its been pressed repeat
loop until its not pressed.

There might be a much simpler solution that does not involve ticking or loops at all - an event based one. It all depends on what you’re trying to achieve, though.

Consider sharing more details to receive a more precise answer.

If Key Pressed, Toggle loop

And here’s what I mean:

253843-capture.png