Custom blueprint node that runs exec pin like function

I’m trying to develop (in C++) a special type of blueprint node. When my blueprint node function reaches a certain point, I need it to stop everything and run whatever is attached to the exec pin. When it’s done running the blueprint node(s) attached to the exec pin, it returns to where it left off in my custom node’s code. Essentially, I want it to treat whatever is attached to the exec pin as a function.

Is this possible?

If what I’ve said isn’t clear, with running an exec pin like a function, I could create my own version of the “for loop” blueprint node. Here’s an illustration:

Now I know how to create multiple exec pins and choose which to run in code (using ExpandEnumAsExecs), it’s the LoopBody() part of the function that I’m having trouble with. So again, is this possible? I assume so, since Unreal has the built-in For Loop blueprint node, but how do I do it?

The For Loop is actually a macro, so you can just double click it and see how it does it.

For C++ a better example of what you want to do is maybe something like UK2Node_DoOnceMultiInput. In particular you do is the visible node that you interact with in the graph is built up to look visually like what you want it to the user facing API to be, however, you implement the ExpandNode virtual function and essentially replace the node in the graph with a collection of nodes that accomplish your actual goals. Another example that might be interesting to you is UK2Node_SpawnActorFromClass. In that case, you’ll see that SpawnActor is actually split in to 2 functions to start the spawn and finish the spawn and in between all of the expose on spawn function sets get inserted.

To see what the ExpandNode actually does (which is basically critical to debugging it, because getting everything hooked up right is always a bit of trial and error), you can enable “Save Intermediate Build Products” under File -> Developer which when you compile will create a few intermediate graphs that show what the expand steps did. Do be careful that you don’t save your blueprints while in that state as some of those intermediate graphs could get included in your actual blueprint and no good will come of that.