I am trying to wrap an RPC service to handle the streaming RPC. E.g. there’s a call that it will be returning multiple messages from time to time. I would like to model it after the “for-loop” node that has a “loop body” pin (that is called multiple times) and a “Done” pin.
I know I can
Use a delegate. I don’t like this as it seems to make the graph unnecessary busy, as a user needs to add an even and pass it as input - and then add handling to the event.
I’ve seen a YouTube tutorial to make multiple output pins (e.g. “Loop Body” and “Output”) so that’s fine.
I was looking how “for loop” node is implemented but it is a subclass of K2Node and such, really complex. I will rather go the delegate route then do a custom K2Node…
The for loop isn’t a K2 node, it’s implemented in normal blueprints via a macro. You can double click on the node to see how it’s implemented (along with a bunch of other similar nodes like while).
That’s probably your best bet- using a blueprint macro library.
Yeah, the two options that you have for for-loop like nodes are macros (this is how array for-each is implemented) or a custom k2 node (this is the enum for each implementation).
Depending on what you’re trying to do, the macro route might work and be pretty easy.
If you absolutely need to do a custom K2 node, I wrote up a tutorial here. That also includes a link to one of my github repo’s which includes a C++ version of the for-each macro as part of making a blueprint for-each for TMaps.
So the trick is a sequence node. Output 1 - loop body, Output 2 - next loop. Pretty easy to implement. Will also look into how they implement the sequence node.