Download

Stacked ForLoop With Delay Doesnt Work

I’m trying to make a macro for a ForLoop with a delay, and it seems to work fine, just added a delay to a copy of the regular ForLoop like someone else has also showed here:

But then when I try to stack them together it doesnt work too well, even if the delay is on 0, if the delay node is there it will be caused, not really sure how to explain the problem with it but I think the index or the loop body just get messed up and they dont work… Can anyone think about a way to make it work?

Really important for my project so hopefully there is a way to make it work…

That stuff probably can be made with event timers or executing whole loop every 0.01 second (ie skipping ticks until 0.01sec passed since last execute). So instead of fighting delays can you explain what you are trying to make?

Generally delays are bad idea in multitasking environment, and i do not trust those delays in unreal, they do not feel like they are real delays, i think they are just event timers that are packed in “Delay” node for blueprints.

Also nested loops can be replaced by single loop, for eg Xyz last index = 202020. Then you calculate your x,y and z out of loop index. z=index mod 20, y= trunc(index/20) mod 20 x=trunc(index/(20*20)) mod 20. There are some edge cases for index<0, but you are starting from 0.

If you are trying to spawn 202020 actors and do not overload caching of assets, you should add single delay after Z loop body pin. But cleaner way is making “pure” function that calculates x,y,z out of index value. Then doing event on timer that fires every 0.01 second and spawns single actor. This way you have much less code, and you can add some fps counter to dynamically adjust speed of spawning.

Thanks for your answer, I will try to explain what I wonna do:
I’m trying to create a world generator based on chunks like in Minecraft, I got it to work but there is a one big performance issue; everytime a chunk generates the game freezes for some seconds, so what I tried to do with the ForLoop with delay is to make it slower so it might help, but I did some tests and figure that if I want to remove this “freeze lag” I will have to make it really slow and thats definitely not what I want.
It might work good in C++ but I dont wonna start learning it just for this, when I have a really good experience with BPs.
I’m using Simplex Noise plugin for the terrain which is blocks, and I got 3 loops there for generating the blocks (Static Mesh Instances), X, Y and Z.
I’m open for every suggestion on how to fix this “freeze lag”, I have no idea what to do and I cant continue my game without fixing it.

For such stuff only one real solution is C++, and even maybe plugin that has everything “heavy” running in separate thread.

So there is no way to fix this lag but redoing it in C++?

Maybe there is way, but in blueprints it will be mess. Try break chunk generation into smaller pieces, instead of delays run chunk generation in few steps.

However such stuff like world generation should be done in C++, and if possible on separate thread that utilizes separate cpu core. This way you do not get any lag in game.