ForEachLoop not working.

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).

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

And then its a second time before its let through both

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.

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

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.

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


Second time


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.

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.

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.

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


I obviously can’t figure out how to attach pictures, can someone tell me? :slight_smile:
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


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

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)

But the delay boolean thing did fix the problem.