Download

Delay make my loop infinite ?

Hello everybody !

Today i was training blueprint, trying to do a generator of mist on my game.
The mist appears in block so i add a delay before set visibility to true to each mist randomly.
Without delay, all seems to work pretty well, but when i add this delay at the beginning of the loop (as the first instruction of the loop), even at 0s, the game detect an infinite loop !
And, if i add this delay at the end of the loop (as the last instruction of the loop) the game skip totally the delay.

Maybe i did something wrong ? What’s your thought ?

Thanks in advance and have a good day !

can you post a pic of the BP?

7ded9b506329844db985e483af68dd21d9f69870.png

In fact i create mist based on the position of 2 TargetPoint, after create them the BP do what you see in the picture.
Mist is the array of mist ^^.
And ReferenceMists is an array of integer wich i use to appear each mist randomly, each index have the value of the index (index 0 → value 0; index 10 → value 10 …).
I randomly chose an index of this array to set the visibility of the Mist array’s index and then i delete this array from ReferenceMists.

I’m not sure if this is the problem, but you have a divide by zero in there. After you remove the final entry from the ReferenceMists array, you will have 1 / 0 as your Delay duration. I’m not sure how UE4 handles that case, but it’s unsafe, regardless.

Hi ddbrown30,

I tryed a delay with a fix value (with 1s and 0s), without succes ^^

Think of the delay node as a “schedule”: it “schedules” the execution of whatever is connected to its “Completed” pin to the future. Therefore, it cannot delay the iterations of a loop/while/foreach node body, just like it cannot delay the execution of the pins in a sequence node (which is what is used inside the loop macro to execute the body pin, check the condition and decide if it executes the pin again or not).

There’s also a bug in your BP: you are reading from “RandomIntegerInRage” twice, which is a pure function. Pure functions are always evaluated when their output nodes are accessed, while non-pure functions store their output values in a “hidden” variable accessible through their output pin. So, this means the index used to select a Mist to call SetVisibility on can be different from the one used to remove an entry from ReferencedMists, because each one will cause a new call to RandomIntegerInRange.

It seems you want to make the SceneComponents in a list randomly become visible in sequence, with a small delay between each one, right? This might be a better approach:

Hi manoelneto,

Thanks a lot for your help, all works perfectly now !
Learning a lot from your post !

Good continuation !

Glad it worked!

Ah, if you need to interrupt the loop (for example, if you need to hide all mist objects suddenly before the loop completed), just call “Clear” on the MistsToShow array.

I noticed that, even with a little duration (1x10e-5s), the mists i spawn seems to takes a long time to appears, is it normal ?