Why does this while loop give me an error?

First thing to do:

Break it apart, play with the first comment, then second etc. Work out when you hook up, the error occurs.

And what are you trying to do, as there may be an easier way to do it and someone may have a more efficient answer with different nodes.

Regards

You can’t have a ‘delay’ within the body of any blueprint loop or function. They don’t play nice together, remove the delays and see if the error goes away. I believe what is happening is the loop function doesn’t actually wait for the delay before executing again and since you have 2 seconds total of delay in this loop body. So the while loop executes continuously for 2 seconds before ever reaching the increment node. In that the number of loop executions exceeds the safety limit set within the engine itself and it crashes.

Hi to everyone, this is my first post on this forum. I came from c++ scripting and this is the first that i use the visual Scripting of Ue4. The problem I have is that when I try to start the project I get an error message that warns me that the while loop is infinite. The logic I used is the same one that I would use for a very banal while loop in c but here it doesn’t seem to work. I thank anyone who can help you understand the error and resolve it. I’m going to leave an image of the code I made. Thank you all

While loops always produce this error in BPs, at least in my experience, and people here strongly advised against trying to use While Loop. I believe that it’s being called numerous times within one tick and that causes the error. You should change the algorithm to use Event Tick or a Timer to do what you want to do.

Actually, you can use delays like that: a delay is called once and cannot be called again until the countdown is over, it’s sometimes quite handy. The thing is, if the operation is only performed once a second, there’s no sense in using a while loop; a looping timer with 1-second interval should do.

You’re right, but there’s more to While Loops in BPs, I think there’s some internal unresolved issue. I’ve tried to use such loops a few times and they always produced that infinite loop error and never ever worked even once.

Haven’t messed with UE4 in a few months but I know you can’t have them inside functions it won’t even let you add the node (I found a work around for that though) but I am pretty sure that using it within a loop body like that won’t work because even though the delay will prevent further execution until the is finished (which is the problem) the loop will attempt to complete its body in the frame that it was called leading to a bunch of executions that are prevented by the delay from actually incrementing the integer condition the loop is checking for hence you run into an infinite loop error.

True, but loops are also tricky…can’t have any logic errors or the loop will instantly find them ha

Thanks guys, if I do not use the delay function in the cycle no error message is displayed but the change in color of the point light occurs instantly without showing the steps from red to green to blue, you know by chance how to increase the duration of each cycle to see the color change far away? Sorry for my bad English but I’m Italian.

Thanks i will try it

You can create a custom delay node following this method that will accomplish what you want. Both videos should work the second is more versatile I believe.

Ok thanks to everyone, I didn’t know that i could make macros on my own so i’ve just created a while loop that accepts delays. Below the new image of the codealt text

Glad you got the custom macro working but now you should delete the delays you have outside the macro… they are unnecessary :slight_smile: