Okay so Im creating an array sorting algorithm in blueprint quickly and Ive come across the issue that if you do happen to cause an infinite loop its not handled at all and it seems to just hang everything. Now ofcoarse generally this is bad but to save a blueprint you typically compile it first (if its incomplete or not) and if it happens to compile incomplete you might get stuck where I am.
I can ofcoarse work around this issue but I thought I would raise awareness and discussion so this can be avoided in the future. One suggestion I might have, that would work in my case, is that auto-magically filling out an array could have a hard set limit, for instance if I said I only wanted my sorted array to store 1,500 elements maximum.
I can understand why the recursion limitation no longer exists but I do believe in regards to blueprint especially in the case of construction scripts, it needs to be handled, if not more gracefully.
In ue3 there was a runaway loop / max iteration count of something like 100000 i think,
and so hangs would not last so long
I can imagine there might be reasons to get rid of the loop iterating limit
i often thought to myself in ue3, what if I want a loop of more than 100000 iterations?
but anyways
I’m just confirming Daniel’s experience from the c++ side of things and also quite curious to see what sort of solution will come up that does not also limit looping potential.
Thanks for the report! I agree that we should handle this particular case more gracefully, especially since we have other scenarios where runaway loops are handled well. I have filed a defect report so hopefully we have a better implementation in future releases.
Your situation - You have a BP that has some work in the construction script, and after adding a fr loop / while loop your editor now freezes and you have to force it to close.
First. Check you logs. They can be found in your Unreal Project folders under ‘\Saved\Logs’
To verify the loop issue is happening you should see in your latest log something along the lines of.
[2023.01.14-21.31.06:274][931]LogScript: Warning: Runaway loop detected (over 1,000,000 iterations) - see log for stack trace
BP_M3_Grid_Manager_C /Engine/Transient.World_0:PersistentLevel.BP_M3_Grid_Manager_C_0
Function /Game/Game/BP/BP_M3_Grid_Manager.BP_M3_Grid_Manager_C:Get All Grid Tiles In Column:01E8
You got a infinite loop.
Create a new blank empty project.
Manually move the uasset for your blueprint into the new project.
Open the project.
The blueprint will be unable to compile, and thus it won’t be able to run the construction script.
Remove the first execution connector from our construction script. Save the blueprint.
Now move it back, and start fixing your object references. Fix the source of the infinite loop BEFORE reconnected that execution node.
Project saved!
It sucks, still a ton of rework, but it will save you from losing the entire BP.
Shame on UE Engine Team for not making this experience less of a PITA.
To add, you can set the Max Loop Iteration Count in the Project Settings → Engine → General Settings → Max Loop Iteration Count. This is really useful for when you need to test something and expect a lag or crash.