# ForEachLoop not working.

**URL:** <https://forums.unrealengine.com/t/foreachloop-not-working/422345>\
**Category:** Audio\
**Tags:** not-working, foreachloop, unreal-engine, loop, Blueprint, question\
**Created:** [April 11, 2018, 5:25am UTC](https://forums.unrealengine.com/t/foreachloop-not-working/422345 "2018-04-11T05:25:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_77df51001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_77df51001](https://forums.unrealengine.com/u/anonymous_user_77df51001)\
**Post date:** [April 11, 2018, 5:25am UTC](https://forums.unrealengine.com/t/foreachloop-not-working/422345/1 "2018-04-11T05:25:17Z")

</div>

Hai again.

Thanks for the help last time and I’m kinda sorry I ran into another problem.

You see, in this case I have a pawn and a static mesh actor that is a One way surface. How I have it set up is that when the player hits space and is crouching then they will go into a loop that will list up all the one way surfaces the actor is stepping on, telling each to let the player through (that’s the function). It all seems to work fine when it’s just one surface and under this logic, it should work for multiple stacking platforms (The loop goes down to each of the overlaps and tells them to let the player through).

 ![237044-pic3.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/e/b/3ebb194420d2e17cc1c4777e33fd4c9e76e54b79.jpeg)

But it doesn’t. For some reason whenever the player is standing on two overlapped platforms. I have to press it two times so it goes through the loop without an input…

Below is the first  
.

 ![237042-pic1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/f/e/8feedb4f6cc97c6d79627d1a2ec5f98c1d146524.jpeg)

And then its a second time before its let through both

 ![237045-pic2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/2/2/422d2d499fa163b22fa03ceb9468100e126f65ff.jpeg)

How can i fix it? or is there a better way to do this?

Also anyone has a suggestion when dealing with custom collision channels? I want to make individual, ones for ai controlled pawns.

---

<div class="post-metadata">

**Author:** ![Dante6686](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dante6686](https://forums.unrealengine.com/u/Dante6686)\
**Post date:** [April 11, 2018, 12:37pm UTC](https://forums.unrealengine.com/t/foreachloop-not-working/422345/2 "2018-04-11T12:37:00Z")

</div>

Your for each loop goes through the array of overlapped actors so is it possible that your ‘sensor’ is not overlapping deep enough and only overlapping top most surface? Maybe do a print string on tick that shows the length of the overlapping actors array and see what it says when you play the game. The length of the array will show how many actors is currently overlapping

---

<div class="post-metadata">

**Author:** ![Dante6686](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dante6686](https://forums.unrealengine.com/u/Dante6686)\
**Post date:** [April 11, 2018, 12:52pm UTC](https://forums.unrealengine.com/t/foreachloop-not-working/422345/3 "2018-04-11T12:52:35Z")

</div>

Actually, I just thought: all that logic and the for loop are being fired when you press space and just this once, so if your character falls onto another surface below that logic and for loop have already finished executing so nothing is going to happen unless you press space again. You could have this whole logic execute on a loop say, while some boolean is true. When pressing space it would set that boolean to true, run the logic on a loop, and only when you release space set the boolean to false and then the logic should stop.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_77df51001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_77df51001](https://forums.unrealengine.com/u/anonymous_user_77df51001)\
**Post date:** [April 11, 2018, 3:13pm UTC](https://forums.unrealengine.com/t/foreachloop-not-working/422345/4 "2018-04-11T15:13:38Z")

</div>

So, I tried the boolean think. I don’t think I implemented it right as the result seemed to be the same as before. I mean, the player character has a collision sphere under it that should detect all overlapping one way floors. Don’t think it’s a matter of not reading them all.

As a test, I appended the length of the array into the print node and interestingly enough get this answer (I still have to jump down twice)  
First time

![237114-pic4.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/c/7/9c72e2398e97abe86af05f9d418f7feed203d1a2.jpeg)

Second time

![237115-pic5.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/e/1/7e1959ff80d47b615bff32da33f9a1acffe67c06.jpeg)

Not sure if this is how the fore loop should work, but the length goes -1 on the second press.

I do thank you for helping.

---

<div class="post-metadata">

**Author:** ![Dante6686](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dante6686](https://forums.unrealengine.com/u/Dante6686)\
**Post date:** [April 11, 2018, 5:24pm UTC](https://forums.unrealengine.com/t/foreachloop-not-working/422345/5 "2018-04-11T17:24:41Z")

</div>

Hi. What I just did was I set up an event in player controller to set ‘JumpDown?’ bool in Character to true when space pressed and false when space released and called an event in character blueprint.  
[1][https://answers.unrealengine.com/storage/attachments/237123-01.jpg](https://answers.unrealengine.com/storage/attachments/237123-01.jpg)

Then, in the character blueprint, the event is to check if ‘JumpDown?’ bool is true and if it is, it’s disabling collision for all platforms the sensor sphere currently touches. When for each loop is completed, it goes back to the branch checking the bool if it’s still true (there has to be a delay node in between, otherwise engine will see it as an infinite loop and that’s bad and it won’t run :). If you’re still pressing space, it will constantly check and set the collision to false and you’ll fall through all obstacles until you release space.  
[2][https://answers.unrealengine.com/storage/attachments/237124-02.jpg](https://answers.unrealengine.com/storage/attachments/237124-02.jpg)

So in your case instead of my event ‘Jumpdown’ going to the branch, you should connect your ‘crouching’ state from your ‘switch on string’ node to the branch.  
Also, when the delay is set to 0.2, the character falls onto a platform below, there’s a very short pause, as if he hit it, and then goes through (I think more realistic). But you can set the delay to 0.01 and it will fall through all platforms without stopping  
[1]:

 ![237123-01.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/5/e/25ef5399811450698ba74d6a54f677c469cbdd05.jpeg)  
[2]: ![237124-02.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/2/2/022d89469c9b84ec6c299a198a9becabe264252c.jpeg)

---

<div class="post-metadata">

**Author:** ![Dante6686](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dante6686](https://forums.unrealengine.com/u/Dante6686)\
**Post date:** [April 11, 2018, 5:27pm UTC](https://forums.unrealengine.com/t/foreachloop-not-working/422345/6 "2018-04-11T17:27:32Z")

</div>

I obviously can’t figure out how to attach pictures, can someone tell me? 🙂  
If you unzip and copy the ‘Platforms’ folder from attached file to the ‘content’ folder of your project (or better new, blank project) you can run the ‘test’ level and see exactly what I did. (I’ve done this in UE4 4.18 so not sure which version you’re using but it should work)  
link text

---

<div class="post-metadata">

**Author:** ![Dante6686](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dante6686](https://forums.unrealengine.com/u/Dante6686)\
**Post date:** [April 11, 2018, 5:44pm UTC](https://forums.unrealengine.com/t/foreachloop-not-working/422345/7 "2018-04-11T17:44:19Z")

</div>

![237127-examplegif.gif](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/d/0/dd0ec98f22d1484fa82450ff89d7f08d182a199d.gif)

This is an example. I’m holding space. First one is with 0.2 delay and second one is with 0.01 delay

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_77df51001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_77df51001](https://forums.unrealengine.com/u/anonymous_user_77df51001)\
**Post date:** [April 13, 2018, 6:47pm UTC](https://forums.unrealengine.com/t/foreachloop-not-working/422345/8 "2018-04-13T18:47:38Z")

</div>

Sorry for the late reply \>\>. I just got around in checking what you sent (or trying to. Mixing projects in unreal sometimes is like unsorting cables blindly. Anyway. I can see what you did (and on that note. I had no idea you could use player controller like that, makes me wonder if i should redo it)

Uploading images in here is kinda easy. I just upload them like you did with the gif (Though don’t use pngs)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_77df51001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_77df51001](https://forums.unrealengine.com/u/anonymous_user_77df51001)\
**Post date:** [April 13, 2018, 7:14pm UTC](https://forums.unrealengine.com/t/foreachloop-not-working/422345/9 "2018-04-13T19:14:22Z")

</div>

But the delay boolean thing did fix the problem.
