Hitting Recursion Limit? Increase Threshold?

I need to know how to override the recursion limit - note that this is not the same as the “max loop iteration count” in project settings. From what I’ve read, I could restructure/refactor a bunch of my logic and have it run in a loop (rather than recursively) to avoid hitting the recursion limit, but that would be a gigantic pain right now.

Once again, I end up answering my own questions here (after hours of frustration). Long story short: Increasing the recursion limit IS possible (in an extremely annoying way, you have to compile the engine from source (you can fork it on Github if you link your Epic and Github accounts) and manually adjust a “define” in ScriptCore.cpp) but sucky.

It’s better to refactor the code - better in terms of “what works with the engine right now” - to use loop control, as the maximum loop count can be easily set in project settings.

Your solution worked for me - thanks a lot! Epic games: please consider exposing this variable to the editor settings.

I was looking for that too, and I found in Unreal 4.27 release notes that the recursion limit (which was changed to default to 120 frames instead of 250), can now be changed in project’s Config\DefaultEngine.ini file (instead of previously requiring a custom build of the engine just to change the limit):

The script execution recursion limit is now stored in a cvar named bp.ScriptRecurseLimit. The default value on desktop is now 120 to match consoles, instead of the previous value, 250. You can set this value higher in the [Console] section of DefaultEngine.ini file if you need to keep the limit at 250 on desktop.

I’ve tried using [Console] section of DefaultEngine.ini file, but as of 4.27.1 it doesn’t seem to work. However, by putting bp.ScriptRecurseLimit in a [SystemSettings] section, like this, it worked for me:

[SystemSettings]
bp.ScriptRecurseLimit=2500
3 Likes

For me this does not seem to work for UE 5.1.1 Is there a new workarround for UE 5?

It still works on my side in a project I’ve been migrating from 4.27 to every new version up to current UE 5.2. Just to be sure, you must restart the editor after editing the Config\DefaultEngine.ini file.

I think you can also edit console variables like bp.ScriptRecurseLimit with the Console Variables Editor plugin, although haven’t tried it.

Also, even after changing the stack frames limit, you can’t set stack frames limit too high, since editor will still eventually run out of stack memory, and crash with a stack overflow error. I wasn’t able on my side to go higher than 5000 frames.

I’ve made some attempts to increase the stack memory size, and might try again another time, but haven’t found yet how it can be done preferably without a custom engine build.