Download

Engine breaking bug

I tried using a WHILE Loop in my level blueprint. Every time I try simulating the level with the WHILE Loop implemented, the engine freezes, and looking at the task manager, it starts rapidly eating up all my system’s RAM.
I have to kill the task in the task manager before it eats all the RAM, and trying it again results in the same problem

Can you post a screenshot of your BP?

Here you go

You have an infinite loop, looks like. You need to have a condition that will evaluate to false when you’re done with the work in the body of the loop. Right now it just loops until “true” which means it will go forever. Thus the engine freeze (I think).

So for instance you might set up a boolean variable, default value true, then after the last spawn command set that variable to false. The next time the loop condition evaluates it will stop because the condition is false.

Of course, it seems more like you’d want a for loop here than a while loop, since I assume you’re trying to spawn these things a certain number of times. You can use a while loop with a counter, just fine, but a for loop will support doing that more cleanly.

It seems pretty stupid for there to be an option to have the condition to be set to positive, to get an infinite loop, if all it will do is crash the engine

Well I mean, that’s all part of programming. That’s how it works in any programming language as well.

It’s the equivalent of



while (true) 
{
    // Stuff happening here.
}


If the condition never becomes false, the loop will continue to execute forever. That code in any programming language (minus weird exceptions), including BP, will result in the program hanging while it sits there looping forever.

The while loop doesn’t support the delay function in the loop body. I’m fairly new to UE4 so I’m not entirely sure why not, but maybe something with how macros work. The solution is easy enough though–just define your own macro with a built-in delay. I put this together quickly and it seems to work in the 5 seconds I took to test it. Obviously, no guarantees though. It’s just a copy of the while loop macro with an extra delay before it rechecks the condition. You can use it as a timer than keeps running the loop at set intervals.

It might not work having two delays nested like you do, but you should be able to achieve the same effect by simply having two delayed loops with a 2 second delay for each.

Hide_Unhide_Inputs.png

This setup right here does what you want… replace the string with whatever you want though :slight_smile: