Nested For Loop issue

This is a section of a custom event on an Actor Blueprint. The event is callable in Editor, and when I call it, it prints “Hello” to the screen. However, if I increase the Last Index value by one, to 11363, it no longer prints “Hello”. What is going on here?

image

it possible you have reached the maximum iteration that can be made at one time, did you get any warning/errors in the output log window ?

Actually, yes! However, this limit is set to the default 1.000.000, so why is this triggered with a measly 11k iterations? Even if this is somehow accumulated by the nesting loop, the array that comes into the outer loop only has 20 items?

It takes everything into account in this tick. What else is going on before you enter the double loop? You should get a warning on the output log, btw.

The log:

LogScript: Warning: Runaway loop detected (over 1 000 000 iterations) - see log for stack trace
Vegetasjon_C /Game/Scenes/StarterScene.StarterScene:PersistentLevel.Vegetasjon_indre_2
Function /Game/Blueprints/Vegetasjon.Vegetasjon_C:ExecuteUbergraph_Vegetasjon:01F9
PIE: Error: Infinite loop detected. Blueprint: Vegetasjon Function: Outputs Call Stack: Show

Everything as in every blueprint in the game?

This is a custom event that is triggered in Editor, so there shouldn’t be anything else running?

The loop in question is right at the start of the event:


The array has exactly 22 items, which works out such that 11362x22 is just below 250k, and 11363x22 is just above. Not a million, but exactly a quarter of a million… don’t know if this is significant.

I think it counts TIME during single tick not iterations or instructions, then they estimate instruction count in error log. Well if i coded that infinite loop detection i would do just that, not sure how exactly epic triggers infinite loop error.

You can solve this (go around error), by triggering event that processes stuff in batches, like single array per tick or per 0.25 sec. Do not use timers for this however. Use either delay(0.2) or on tick check if 0.2 sec passed before triggering next one.

1 Like

Everything as in every blueprint in the game?

No, in this execution chain, in this frame.

This is a custom event that is triggered in Editor, so there shouldn’t be anything else running?

What triggers the event and how?

Yup iteration represent recalling the same node.

If you double click a ForEach node, you will see that it contain even more nodes inside, so it can quickly add up.
A 11k for each loop actually represent more than 11k iterations in total combine(at a moment).

OK, thanks guys, I guess I have my answer. This was just some debugging I did to troubleshoot some other issue, so just bumping up the iteration limit solved my problems.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.