I am Currently writing a terrain generator for a Retro Tycoon game, using blueprints and Instanced static meshes, quite a few of them. and when i generate small world sizes everything works great but as soon as i go over 250 X 250 my code generates the “infinate loop” error, meaning it stopped the loop because i ran past 1 million iterations.
The code is a for loop for the Y with a nested for loop for the X inside, that then assings things like biome and location data to the tile, running likely on a single thread. and looks like this :
When searching for solutions to this problem, i have seen people suggest to just raise the limit in the engine settings, but that feels like a bit of a hack for me and I was wondering if there is a way that i can restructure or re desing my code so that it does not trigger this error to begin with?
Hope that explained it well enough, ells i am more then happy to try and elaborate.
Try breaking up the giant loop into smaller loops. Do 100k tiles. Deep breath. Do another 100k. Breathe…
There’s a new node in UE5 called Delay Until Next Tick - perhaps it’d be enough here.
With a lot of breaks like that and smaller steps, you may have enough time to update a progress bar that indicateds the progress, for example.
Another way is to iterate more slowly, so it all does not happen in a single frame. You could use a fast firing timer to churn out chunks of tiles many times per frame.
Thanks for taking the time to help me out back in September, i sadly lacked the understanding to properly implement you suggestions, untill now, i am pleased to report that it works, through a lot of trial and error i also figure out what made it not work, Nested forloops does not work well with delays of any kind, and breaks the itterations. but moving it to the loop worked wonders, it is slow with the big map sizes but i get past the infinate loop detected so that i a plus.