# Using A Loop To Streamline This CODE

**URL:** <https://forums.unrealengine.com/t/using-a-loop-to-streamline-this-code/1894881>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question, Blueprint\
**Created:** [June 8, 2024, 7:23am UTC](https://forums.unrealengine.com/t/using-a-loop-to-streamline-this-code/1894881 "2024-06-08T07:23:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leomerya12](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/leomerya12/32/926321_2.png) [@Leomerya12](https://forums.unrealengine.com/u/Leomerya12)\
**Post date:** [June 8, 2024, 7:23am UTC](https://forums.unrealengine.com/t/using-a-loop-to-streamline-this-code/1894881/1 "2024-06-08T07:23:43Z")

</div>

Hello,

I’ve been at this for hours, so I figured I’d reach out to help save me time. I’m trying to test for multiple instanced overlaps, and I’m successful here:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/3/c/03cb1ab485c54015a7e72359b2bc9b8f57a191c6.jpeg)

However, I know there’s a better way. I’m missing something in how ForLoops function, because this doesn’t work:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/c/c/1cc56822acb3826c03e8f81750d750cf828336f9.png)

I thought it would run the function each time with a different index, but maybe I haven’t set it up correctly? Unsure.

---

<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:** [June 8, 2024, 7:38am UTC](https://forums.unrealengine.com/t/using-a-loop-to-streamline-this-code/1894881/2 "2024-06-08T07:38:34Z")

</div>

Add a tag to the components and check for that?

Are there more instances in the world? Spawned at runtime or placed in level?

Why not just check the class of the other actor?

---

<div class="post-metadata">

**Author:** ![Leomerya12](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/leomerya12/32/926321_2.png) [@Leomerya12](https://forums.unrealengine.com/u/Leomerya12)\
**Post date:** [June 8, 2024, 8:04am UTC](https://forums.unrealengine.com/t/using-a-loop-to-streamline-this-code/1894881/3 "2024-06-08T08:04:55Z")

</div>

> [@pezzott1](#):
>
> Why not just check the class of the other actor?

Hey,

Normally, yes, however, the issue is that there is a specific component that is overlapping that I do not want to overlap. I’m going to scrap this project, as it was merely for learning, but I do want to figure out why my FOR LOOP is incorrect.

> [@pezzott1](#):
>
> Add a tag to the components and check for that?

This is not scalable. At least, retroactively. HOWEVER, it is a great tip, nonetheless.

---

<div class="post-metadata">

**Author:** ![Leomerya12](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/leomerya12/32/926321_2.png) [@Leomerya12](https://forums.unrealengine.com/u/Leomerya12)\
**Post date:** [June 8, 2024, 6:24pm UTC](https://forums.unrealengine.com/t/using-a-loop-to-streamline-this-code/1894881/4 "2024-06-08T18:24:35Z")

</div>

BUMP

---

<div class="post-metadata">

**Author:** ![zeaf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zeaf/32/1108035_2.png) [@zeaf](https://forums.unrealengine.com/u/zeaf)\
**Post date:** [June 8, 2024, 6:36pm UTC](https://forums.unrealengine.com/t/using-a-loop-to-streamline-this-code/1894881/5 "2024-06-08T18:36:24Z")

</div>

In your second picture, the branch has a condition of True, and you’ve only connected code to the false path, so that will never run

---

<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:** [June 8, 2024, 7:15pm UTC](https://forums.unrealengine.com/t/using-a-loop-to-streamline-this-code/1894881/6 "2024-06-08T19:15:48Z")

</div>

it’s all guess work until we get more info about the problem. Maybe the design is the problem?

---

<div class="post-metadata">

**Author:** ![Leomerya12](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/leomerya12/32/926321_2.png) [@Leomerya12](https://forums.unrealengine.com/u/Leomerya12)\
**Post date:** [June 8, 2024, 8:02pm UTC](https://forums.unrealengine.com/t/using-a-loop-to-streamline-this-code/1894881/7 "2024-06-08T20:02:23Z")

</div>

> [@zeaf](#):
>
> In your second picture, the branch has a condition of True, and you’ve only connected code to the false path, so that will never run

You’re correct. I was being lazy. (Didn’t want to redo everything again.)

Here’s what the code actually looked like:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/0/e/40e9613c1286ea5774ee23d7c40788e9ee6c4835.jpeg)

Shouldn’t it behave identical to this?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/3/c/03cb1ab485c54015a7e72359b2bc9b8f57a191c6.jpeg)

> [@pezzott1](#):
>
> it’s all guess work until we get more info about the problem. Maybe the design is the problem?

I just want to know if I set this up incorrectly. My approach is wrong (for what I want) but I want to know why my understanding of the For Loop is incorrect.

---

<div class="post-metadata">

**Author:** ![baobao4435](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/baobao4435/32/950790_2.png) [@baobao4435](https://forums.unrealengine.com/u/baobao4435)\
**Post date:** [June 8, 2024, 8:15pm UTC](https://forums.unrealengine.com/t/using-a-loop-to-streamline-this-code/1894881/8 "2024-06-08T20:15:10Z")

</div>

You connected them all to other actor…the first picture has something connecting to other component.

I’m unconfident with my English so I draw a picture 🙂

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/d/8/fd89beda5222f02617449026cda8cb835fa36289.jpeg)

---

<div class="post-metadata">

**Author:** ![Leomerya12](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/leomerya12/32/926321_2.png) [@Leomerya12](https://forums.unrealengine.com/u/Leomerya12)\
**Post date:** [June 8, 2024, 9:06pm UTC](https://forums.unrealengine.com/t/using-a-loop-to-streamline-this-code/1894881/9 "2024-06-08T21:06:19Z")

</div>

> [@baobao4435](#):
>
> I’m unconfident with my English

I’m not even going to try to begin to write Chinese, so, yes, your English is great.

I know this sounds hokey, but I wish I can give everyone credit, because you all helped me get to resolution of this issue. Bao pointed something out that would have driven me nuts, so, there’s that.

The problem was the the loop was only taking the LAST variable value. So, conditions would be:

1,0,1 → 1  
1,0,0 → 0  
0,1, 1-\> 1

etc.

I noticed that if I changed the “Last Index”, the bombs would only work in THAT index.

So, I understand loops, thankfully, but my logic was incorrect.

---

<div class="post-metadata">

**Author:** ![Auran131](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Auran131](https://forums.unrealengine.com/u/Auran131)\
**Post date:** [June 9, 2024, 3:53am UTC](https://forums.unrealengine.com/t/using-a-loop-to-streamline-this-code/1894881/10 "2024-06-09T03:53:56Z")

</div>

not really the question but this is a good use for an interface, just call ActivateTurret or whatever and on the target if it implements the interface run any addition checks there.

fire and forget

---

<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 9, 2024, 3:54am UTC](https://forums.unrealengine.com/t/using-a-loop-to-streamline-this-code/1894881/11 "2024-07-09T03:54:33Z")

</div>

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