Download

Serious suggestion about the for each loop node

I just resolved a bug I had in my code which was driving me crazy for 3 weeks.
The lack of the suggestion I want to make below caused me to suspect the wrong nodes for causing the problem
and I think if this simple feature is added it would have saved me a lot of headache.

The problem in short was:

  1. For 3 weeks I was getting the wrong data written into sav files via the save to slot node.
  2. First I thought it was the reference variable I was creating right after the save game object node so
    that resulted in me not creating one but rather long spaghetti lines all over my event graph.
  3. Then the problem became worse when I ran my laptop in battery mode.
  4. The problem also became worse right after a Windows update.

So first I thought the issue was the reference variable so I stopped using that.
Then I thought it was running UE4 in battery mode on my laptop.
Then I thought the problem was Windows update that broke something.
I spent a lot of time updating and adding to Visual Studio installs because I thought that might have something to do with it.
Then I thought the save game to slot node was bad and I was jumping from one BP to another trying to figure out why its not working
and why I am getting wrong data written into wrong slots.

Well … after 3 weeks of intermittent pain I finally figured it out.
It was none of the above actually.
It was a for each loop node (macro) where I was using the wrong output pin.
I was coming out of the loop body output pin and not completed output pin.

So as the speed of my machine was affected the loop was either completed or not.
And it was never consistent because the speed of my machine wasn’t so that makes sense to me now.
Now that I understand what was going on.

The bad thing was and I believe this added feature would be a great help, that the for each loop
node does not tell you if it completed its loop or not.
That killed me.
It was just getting the wrong information (not catching the latest updated info) from a variable in another BP.
Because it never completed the loop.
I was totally unaware of this and this let me to believe that all those other issues mentioned above might be the problem.

Below I am making a suggestion that would take care of this problem.
By simply adding a warning like you have on the casting node.
That would simply warn you that your loop did not complete and that you should
rather use the completed output pin. :slight_smile:
I really think this would be a great addition.
TY

The ‘Completed PIN’ is entirely optional though, so how would you make this work in practice (assuming I’m understanding you right). Generally I do think it’d help to have a guide for commonly used nodes and graphs that captures common mistakes. And have this guide built inside the graph along with each node (as hit & miss tooltips don’t cut it). However Epic mgt seem preoccupied with giving dev grants to YouTubers than adding something like this that’d be very practical.

For example the single biggest mistake you see devs making all the time with ForEachLoops etc is forgetting that you can’t wire a DELAY into the ‘Loop Body’. Its even easy for experienced devs to make this mistake (when working far away downstream from the loop body :o). That and the gotchas of using Macros vs Functions and Timelines and Components. All the crucial does & donts / pros & cons of BP are completely absent from the editor. Seems really short-sighted imho…

Yep. Also some of us dont even come from a coding background se we have to break many bones before we learn what is probably obvious to most coders :slight_smile:

Wouldn’t it be great to have like a top 10 list of most common mistakes made by devs in UE4?
I know it might make the engine look bad so for political reasons it might not be a good idea but I would certainly wanna read that. :slight_smile:

I don’t think it would be a bad PR move at all whatsoever… It would actually be a useful Doc.
But Epic management DGAF tbh. Its always been about pushing the tech forward for them.
Which is understandable as a business, they want to be ‘the sht’ for the next decade or two.
But that always comes at a cost, as some devs will quit and leave for other engines (godot).

Well any engine will have issues like every program out there.
So changing game engine is not very smart because then you just have new problems you dont know yet. :slight_smile:

Once you figure out the issues in UE4 its better to stick with it.

Here is my BP cleaned up using reference variables since I can trust them now I figured out they were not the problem after all.
Every slot is now writing out 100% correct

:-))))

I do notice its just a tiny bit slower probably because I am completing the loops now.
I dont know if the use of the reference variables slows it down a tiny bit too.

Try this article :slight_smile:
https://www.ue4community.wiki/Fundamental_Blueprint_Practices

Epic actually prepared a few talks and pages on how common pitfalls of blueprints. The editor is not a place for it however, for things like video streams :wink:
Documentation hub should gather all such resources for all the beginners…

Great thank you!

Yeah of course I never heard of that.

I watched part one of Blueprints In-depth - Part 1 Unreal Fest Europe 2019 Unreal Engine and I learned more in that one video I learned in 6 years in Unreal.
I really wish I saw this 6 years ago.

I just solved my entire problem with the for each loop on the level BP.
I just discovered you can actually send variable values to the level BP via Event Dispatchers.
Thats HUGE.
Bye, bye for each loop.
I didn’t know you could do that. You simply create inputs on the event Dispatcher :cool: :rolleyes: