Infinite Loop

Hi all,
Is there a way to prevent the infinite loop error I’m having and still use this recursive function?

Use For Loop with Break and break the loop before calling the function again. If you are still getting infinite loop try increasing the loop count: Project Settings → Engine → General Settings → Max Loop Iteration Count. If that doesn’t work than you probably do have an infinite loop.

Not sure what the function should do, but it looks like you are calling the FillHitsArray function inside itself, which can loop forever. You need to create variables for the arrays that will store the hits. The way it is setup it is sending the arrays to the input of the same function which it not storing it anywhere.

First off a new frame cannot start until all loops have finished. You’re re-calling a function with a loop in it…in the same frame. So 1FPS would eventually be the outcome once the array count starts to build. So completely remove the recall from the function.

Secondly, recursive calls should be done on “completion”… Completed pin → call → return.


In all honesty without seeing the bigger picture of what you’re doing I can’t give you a sufficient answer.

From what is shown I’d just call the function on tick. This will have it run every frame instead of trying the recursive.