C++ output params setup for a forloop node

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.

Thanks :wink:

https://wiki.unrealengine.com/Bluepr…lueprint_Nodes

Right at the very bottom in the advanced section should be everything you need. iirc exec pins are just delegates.

Hi,
I see I can find many nodes in source but others like “sequence” seems impossible.
Do you know if Is there any way to access its source in C++?

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.

ExpandEnumAsExecs:

https://forums.unrealengine.com/development-discussion/c-gameplay-programming/82648-custom-nodes-with-multiple-exec-pins

@BrUnO_XaVIeR but could I make a custom out pin that runs the loop body iteration with the “ExpandEnumAsExecs”?

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.

Improving UE4 Blueprint Usability with Custom Nodes - Engines and Middleware - Tutorials - GameDev.net

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

1 Like