How can I fix this infinite loop?

I am trying to setup a play button on the main menu of my project which loads the user into the game world, but when I click play I get a “Infinite Loop Detected” error in the message log. If I click show, it brings me to the ‘StandardMacros → ForLoop’ section and highlights the “Assign Value to Variable” node. My construction script for my world floor is identical to the one in this youtube video:
[link text][1]

The issue is not with the loop per se, post the script you execute instead. We can’t see what you’re up to.

what is the start and end of your loop?

I posted the Construction Script that executes for the world ground terrain. It works fine on its own, but when I add in a play button, it crashes the simulation on click. All I have setup for the play button is ‘On Clicked’ which goes to ‘Open Level (by Name)’ to open my map.

I updated my post. I added in the Construction Script for my world terrain generation. It includes the ForLoop for the generation.

Do you think changing my Tile Size, Heights, and Frequencies to ‘Set’ rather than ‘Get’ would make a difference? Does it not know the parameters to generate if it is on ‘Set’ ?

This is only due to the unreal limitations of the engine and you can not work with a large loop. If your problem is solved, it’s because you have reduced the “width” and “length”, so if you increase your size it will happen again.
I made a simple code for you to solve your problem. This will take your loop and turn it into simple pieces.

Part1:link text
Part2:link text

Ah yes, it was because of the length and width. I did not realize I had made the ground smaller. Thank you for the help. However, I am very new to unreal engine and have essentially 0 programming experience. I do not quite understand what I am supposed to add into your fixed code.

Instead of using 2 for, use my code and enter your code logic in part 2. Comment wherever the code was incomprehensible to you, I will answer. Only for part 2, you must first create a function

I’ll be honest, I don’t really understand what I need to add/change on either of the parts for it to work the way I want it to. I was already lost at what to do with the blue highlighted function. I just imitate a lot of YouTube tutorials that I find online since I do not know how to program things on my own. I know what I want to do, but not HOW to do it/implement it. Since I lack programming knowledge, it is very difficult to understand what I am supposed to add to these parts you have created. Sorry if this was a waste of your time.

This is your logics + my logic

link text

I’m glad I was able to help you. Please confirm the answer if you get it to remove it from the unanswered questions, and give it a vote if you like.

@Chief Man - so how many instance are you creating?

“Infinite Loop Detected”

By default you can spawn only that many in a single execution loop. Increase this value past what you need for now and run your script as is:

Don’t put it too high, it’s supposed to catch issues like this.


Next time when you need to do a huge number of something, divide the task into parts. Spawn 50k of something, wait, 50k, wait and so on. Otherwise you’ll end up with a very unresponsive system that is prone to crashing if things go wrong. As they often do.

1 Like

I’ll try it out right now. Thanks for all the help. There’s a bunch of errors, but it’s only because I need to add in the new variables to my event graph.

Do you mean how many instances of the world terrain? If so, I would like to create enough to have at least a 2000x2000 block map. Is it better to create multiple smaller instances rather than one large instance? Is that how you make individual chunks?

Also, in the “part2” link that you sent, how do I create that “My Loop Body” node? I can’t figure out how to add that to mine, and I can’t copy then paste it into my project.

create enough to have at least a
2000x2000 block map.

Yeah, with that many you’re simply exceeding the loop limit. Can’t recall what the default is but it’s probably 200k and you’d need more than 4 milion…

Is it better to create multiple
smaller instances rather than one
large instance? Is that how you make
individual chunks?

The answer to this question is quite complicated. But yes, you do not want 4 million instances in a single (H)ISM. You should absolutely consider finding a way to create chunks. The reasons for this are too numerous to list here.

But most importantly, this is very exaggerated culling (just to demo it):

Image from Gyazo

If you’re too far from something or can’t see it (it’s behind you), it’s not drawn - this can save a lot of performance. Sadly, Instanced Static Meshes cannot do it on per-instance basis. So you’re either drawing 4 million of them or they’re all gone.

That’s why Hierarchical Instanced Static Meshes exist - that’s what in the animation. Some of them can be hidden and not drawn when not needed. And they also support LOD - level of details.

Different colours here indicate distance from the camera. The further away we are, the lower LOD can be applied; again, saving even more performance - and HISMs do it automatically once you set it up.

Instanced Static Meshes (ISM) are great if you have a numerous group of something that is close together and almost always will be visible in full. Think clumps of trees. You can have numerous ISM component and at least hide those components.

Hierarchical Instanced Static Meshes (HISM) meshes are better for huge amount that does not need to be always seen at all times - like a tile map with 4m tiles! I’d still divide it into much smaller chunks of, lets say, 10k. Even fewer - depending on the viewpoint. In a top down game you’d need fewer than in Minecraft, for example.

But again, it’s hard to advise as I don’t know what you’re up to and what your project’s requirements are.


For more info, here’s one of the better videos on the subject imho:

How can I make it generate chunks at a time rather than the entire map at once like you’re suggesting? Once I make the map larger than 500x500 blocks, it crashes when I click the Play button on the main menu during simulation.

I essentially want to copy how the game “Trove” does their world generation. I want a procedurally “MC-style” cube/block generated map that allows players to break any block on the map, even the dungeons that I am spawning across the map.

I like the culling example that you showed above. I can use it as a render distance.