Creating a custom foreach loop for a Blueprint in C++

Hey guys,

I’m trying to create a custom foreach loop in C++, while it kinda works, the layout in the BP is bit strange.

I would like to have a “loop body” exec pin on the right instead of having a delegate with a custom event at the lower left corner

image

I declared the function like this:

DECLARE_DYNAMIC_DELEGATE_FourParams(FNeighbourResult, EBCMapElementNeighbourDirectionBits, Bit, bool, IsSet, FVector, Dir, FRotator, Rotation);

UFUNCTION(BlueprintCallable, Category = "BCMapElementModuleActor")
void ForEachNeighbour(EBCMapElementNeighbourDirectionBits Bits, const FNeighbourResult& Result);

Any help is appreciated, thanks!

This isn’t really possible in C++ without using K2 nodes.
The foreach loop was created in blueprint- you can double click it to see the standard blueprint macro library it’s made in.

Try to look through that and see how it’s made. If you need help on how to implement your specific loop, just let me know and I’ll be happy to provide an example.