# Making my brake run in a loop without error

**URL:** <https://forums.unrealengine.com/t/making-my-brake-run-in-a-loop-without-error/1911860>\
**Category:** Game Development\
**Tags:** infinite-loop, unreal-engine, loop, Blueprint, question\
**Created:** [June 21, 2024, 6:51pm UTC](https://forums.unrealengine.com/t/making-my-brake-run-in-a-loop-without-error/1911860 "2024-06-21T18:51:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DripTheSeawing](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/driptheseawing/32/951357_2.png) [@DripTheSeawing](https://forums.unrealengine.com/u/DripTheSeawing)\
**Post date:** [June 21, 2024, 6:51pm UTC](https://forums.unrealengine.com/t/making-my-brake-run-in-a-loop-without-error/1911860/1 "2024-06-21T18:51:37Z")

</div>

Im trying to make a mechanic for my marble racing game where you can brake to slow yourself rapidly to allow for tighter turns. Every time I try to test out the code I get a “Infinite loop” error. Is there any way I can work around this so it wont give me this error while still doing what I want it to do?

 ![image_2024-06-21_134943567](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/f/7/0f7f548254606869f698f68452b35623e80572a6.jpeg)  
Here’s my code for braking

---

<div class="post-metadata">

**Author:** ![Monz](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/monz/32/1194614_2.png) [@Monz](https://forums.unrealengine.com/u/Monz)\
**Post date:** [June 22, 2024, 6:34pm UTC](https://forums.unrealengine.com/t/making-my-brake-run-in-a-loop-without-error/1911860/2 "2024-06-22T18:34:16Z")

</div>

Hello, based on the reference image:

- The InputAction should only be used to toggle the Boolean value.
- There’s no need for the WhileLoop, I would do such checks OnTick.
- You can connect the ReturnValue (Boolean) of the LineTraceByChannel directly to the Branch, there’s no need to check if it equals True.

Here’s an image for your reference:

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/c/3/bc31e5d1b650daa89874c19515080b3a13eefe64.jpeg)

Please keep in mind that this is just a suggestion based on the image reference you provided.

I hope it helps!

---

<div class="post-metadata">

**Author:** ![DripTheSeawing](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/driptheseawing/32/951357_2.png) [@DripTheSeawing](https://forums.unrealengine.com/u/DripTheSeawing)\
**Post date:** [June 23, 2024, 7:19pm UTC](https://forums.unrealengine.com/t/making-my-brake-run-in-a-loop-without-error/1911860/3 "2024-06-23T19:19:48Z")

</div>

Ok, thanks, will this cause the game to lag? since in runs every tick.

---

<div class="post-metadata">

**Author:** ![Monz](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/monz/32/1194614_2.png) [@Monz](https://forums.unrealengine.com/u/Monz)\
**Post date:** [June 24, 2024, 1:49pm UTC](https://forums.unrealengine.com/t/making-my-brake-run-in-a-loop-without-error/1911860/4 "2024-06-24T13:49:24Z")

</div>

Relying heavily on Event Tick can indeed affect your game’s performance, but not in this case as it’s just a simple line trace and it only runs when Brake is pressed. The only case where this _might_ affect performance is if Trace Complex was set to True + the Actor was on top of a very complex mesh.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [July 24, 2024, 1:49pm UTC](https://forums.unrealengine.com/t/making-my-brake-run-in-a-loop-without-error/1911860/5 "2024-07-24T13:49:35Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
