Hello, I have started to develop my own Blueprint Function library in C++ and I was wondering how should I setup a custom ForLoop node to have the same output nodes than the default one (attached pic). I was also wondering what is the process to call the exec pins like “LoopBody” inside my for loop.
I couldn’t find either the ForLoop node in the engine source. I guess because it is really a macro.
If there is some tutorial about this specific tasks I would appreciate a link.
The for loop node is actually a blueprint macro, not C++. If you double click it you will see the source BP. The sequence node is not a UFUNCTION, I think, it’s probably an K2_Node directly, like the IF node.
Yes, I noticed that about the ForLoop and how expensive it is in BP. I don’t understand why there’s not a native function implementation so I tried to do on my own, but I can’t find a guide on how to create all the needed pins.
No, you can’t replicate a ForLoop node using the ExpandEnumAsExec meta markup. It’s not possible for a plain UFUNCTION to trigger multiple outputs in a way that looks like the ForLoop/ForEach node.
You’d have to resort to an entirely custom blueprint node. I wrote a tutorial on that a few years back and nothing’s really changed from UE4 to UE5.
It also links to a github repo I setup (GitHub - MagForceSeven/UE-K2-Nodes: Examples of custom K2 Nodes for use in Unreal Engine 4/5) to show an example implementation of a ForEach node that allows iterating TMaps (something the engine surprisingly lacks). It also includes a reimplementation of the ForEach macro in native, but only because the macro is inaccessible to the ForEach node I was trying to make.
However, there’s really no good reason to re-implement it just for it to have a native implementation. If perf really comes down to a for loop, you should probably just reimplement the whole loop in native instead of going back and forth between native (for the loop control) and blueprint (for the body).