Infinite script recursion (250 calls) detected - how to bypass it?

I get this warning (+ infinite loop error) from my construction script which has some recursive functions.

“Infinite script recursion (250 calls) detected (…)”

It’s possible that it indeed reaches 250 calls, but how to bypass this limit? For ‘infinite loop’ error we can set ‘Max Loop Iteration Count’ in Project Settings, but I don’t see anything for max recursion calls. Any clues?

I would really like to get a clue about it as well. Since I’m having a function needing to be called legitimately about a 1600 times (it’s not for real-time purpose, but rendering.)

I’m hitting the same issue in a different context. I’m controlling the loops with a counter, but it still spits out the error.

Just ran into this too. I want to add stuff along a spline during construction, and after 246 recursive iterations it detects an infinite loop.

For some reason. Having a loop in a loop in my tick event that calls a couple of functions a couple thousands of times is fine. Could you try to move this part of your script from your construction script to the Begin Play event?

You may also want to try to do the things you do in your function outside of it (like taking it out and putting it in the graph rather than having a function)

I did work out a work/around by instead of using a recursive function, I use a for loop. Start index 0, and last index a variable. During the loop, I query if this is the last iteration, and if not, I add 1 to the variable, so that it keeps increasing by 1 until the query is met.

That’s the solution I ended up with as well.

Engine protect the BP vm with recurse limit to prevent the Editor process to be terminated accidentally. With desktop platform, it’s set to 250 with the recursion limit. If you got a source engine version, you can enlarge it as your own responsibility while you know what it may happen. Check ScriptCore.cpp and change RECURSE_LIMIT to a acceptable value your recursive function may achieve.

Thank you. I wish there was a way to change it in the Engine config files or project settings

Thanks for the answer, but super sad.

One way around this without an engine modification is to duplicate your recursive function, if original function is recursive1 then name duplicate e.g. recursive2 now from recursive1 call recursive2 and from recursive2 call recursive1.

No more warnings generated (and no more performance hit from generating that warning message).

1 Like

“bp.ScriptRecurseLimit” setting was added in DefaultEngine.ini file in version 4.27, see this thread.

1 Like