Loop made from Custom Events incorrectly flagged as infinite loop.

This loop should never fire infinitely. However, if you call it in PIE it throws an infinite loop detected error. If you call it in editor, it will just add 118 integers to Int Array then quit, when it should add 200 elements to Int Array (4 sets of 0-49). What’s going on here?

I attached a copy of the uasset if anyone wants to drop it into their content folder to test it out.

Edit:

Okay now check this out. Instead of calling the custom events I instead connected the wire’s directly into the nodes flow that they call. And now it no longer is detected as an infinite loop and the Array is filled as expected.


so I guess spaghetti is on the menu

It is actually not infinite loop. Blueprint recurse limit exception. Changing max inner loop index to small(10<) it works expected.

ScriptCore.cpp



DEFINE_FUNCTION(UObject::ProcessInternal)
{
...
        else if (++FBlueprintExceptionTracker::Get().Recurse == RECURSE_LIMIT)
        {
            // If we have a return property, return a zeroed value in it, to try and save execution as much as possible
            UProperty* ReturnProp = (Function)->GetReturnProperty();
            ClearReturnValue(ReturnProp, RESULT_PARAM);

            // Notify anyone who cares that we've had a fatal error, so we can shut down PIE, etc
            FBlueprintExceptionInfo InfiniteRecursionExceptionInfo(
                EBlueprintExceptionType::InfiniteLoop,
                FText::Format(
                    LOCTEXT("InfiniteLoop", "Infinite script recursion ({0} calls) detected - see log for stack trace"),
                    FText::AsNumber(RECURSE_LIMIT)
                )
            );

...



On PLATFORM_DESKTOP recurse limited to 250. I think every blueprint node’s recurse counted(250>), event thought IntArray 118.



#if !PLATFORM_DESKTOP
    #define RECURSE_LIMIT 120
#else
    #define RECURSE_LIMIT 250
#endif


I am able to change max Inner Loop index to 100 and Outer to 10 and successfully add 1,000 elements to the array using the method in the second pic. So it is just calling custom events that has a recursive limit?

Yes. UObject::ProcessInternal called on custom event. I don’t know why FBlueprintExceptionTracker::Get().Recurse != loop custom event call count.