# Infinite Loop

**URL:** <https://forums.unrealengine.com/t/infinite-loop/1171776>\
**Category:** Blueprint\
**Tags:** infinite-loop, unreal-engine, UE5, Blueprint, question\
**Created:** [May 19, 2023, 9:46pm UTC](https://forums.unrealengine.com/t/infinite-loop/1171776 "2023-05-19T21:46:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![T4l\_R](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@T4l\_R](https://forums.unrealengine.com/u/T4l_R)\
**Post date:** [May 19, 2023, 9:46pm UTC](https://forums.unrealengine.com/t/infinite-loop/1171776/1 "2023-05-19T21:46:11Z")

</div>

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

 ![Untitled](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/d/7/ed7cdb35331e99a8f8d2739b4c5f5ec0f1a4b989.png)

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [May 19, 2023, 10:41pm UTC](https://forums.unrealengine.com/t/infinite-loop/1171776/2 "2023-05-19T22:41:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sarlack](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sarlack/32/1194542_2.png) [@Sarlack](https://forums.unrealengine.com/u/Sarlack)\
**Post date:** [May 19, 2023, 11:52pm UTC](https://forums.unrealengine.com/t/infinite-loop/1171776/3 "2023-05-19T23:52:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rev0verDrive](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rev0verdrive/32/907214_2.png) [@Rev0verDrive](https://forums.unrealengine.com/u/Rev0verDrive)\
**Post date:** [May 20, 2023, 12:38am UTC](https://forums.unrealengine.com/t/infinite-loop/1171776/4 "2023-05-20T00:38:21Z")

</div>

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.
