# Making a UFUNCTION that calls output pin multiple times.

**URL:** <https://forums.unrealengine.com/t/making-a-ufunction-that-calls-output-pin-multiple-times/1337087>\
**Category:** C++\
**Tags:** unreal-engine, custom-nodes, Blueprint, question\
**Created:** [October 18, 2023, 8:41pm UTC](https://forums.unrealengine.com/t/making-a-ufunction-that-calls-output-pin-multiple-times/1337087 "2023-10-18T20:41:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![euoss](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@euoss](https://forums.unrealengine.com/u/euoss)\
**Post date:** [October 18, 2023, 8:41pm UTC](https://forums.unrealengine.com/t/making-a-ufunction-that-calls-output-pin-multiple-times/1337087/1 "2023-10-18T20:41:14Z")

</div>

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

1. 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.
2. 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…

---

<div class="post-metadata">

**Author:** ![rokenrock](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rokenrock/32/1040844_2.png) [@rokenrock](https://forums.unrealengine.com/u/rokenrock)\
**Post date:** [October 18, 2023, 8:59pm UTC](https://forums.unrealengine.com/t/making-a-ufunction-that-calls-output-pin-multiple-times/1337087/2 "2023-10-18T20:59:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![euoss](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@euoss](https://forums.unrealengine.com/u/euoss)\
**Post date:** [October 18, 2023, 10:41pm UTC](https://forums.unrealengine.com/t/making-a-ufunction-that-calls-output-pin-multiple-times/1337087/3 "2023-10-18T22:41:56Z")

</div>

Thanks. I will take a look later when I have some time.

I actually looked at [for each enum value](https://github.com/EpicGames/UnrealEngine/blob/5ccd1d8b91c944d275d04395a037636837de2c56/Engine/Source/Editor/BlueprintGraph/Private/K2Node_ForEachElementInEnum.cpp#L154) node. That’s the scary one…

---

<div class="post-metadata">

**Author:** ![MagForceSeven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/magforceseven/32/906563_2.png) [@MagForceSeven](https://forums.unrealengine.com/u/MagForceSeven)\
**Post date:** [October 18, 2023, 11:18pm UTC](https://forums.unrealengine.com/t/making-a-ufunction-that-calls-output-pin-multiple-times/1337087/4 "2023-10-18T23:18:27Z")

</div>

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](https://www.gamedev.net/tutorials/programming/engines-and-middleware/improving-ue4-blueprint-usability-with-custom-nodes-r5694/). That also includes a [link to one of my github repo’s](https://github.com/MagForceSeven/UE-K2-Nodes) which includes a C++ version of the for-each macro as part of making a blueprint for-each for TMaps.

---

<div class="post-metadata">

**Author:** ![euoss](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@euoss](https://forums.unrealengine.com/u/euoss)\
**Post date:** [October 18, 2023, 11:19pm UTC](https://forums.unrealengine.com/t/making-a-ufunction-that-calls-output-pin-multiple-times/1337087/5 "2023-10-18T23:19:29Z")

</div>

Thank you! This is extremely helpful.

---

<div class="post-metadata">

**Author:** ![euoss](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@euoss](https://forums.unrealengine.com/u/euoss)\
**Post date:** [October 19, 2023, 3:09am UTC](https://forums.unrealengine.com/t/making-a-ufunction-that-calls-output-pin-multiple-times/1337087/6 "2023-10-19T03:09:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [November 18, 2023, 3:09am UTC](https://forums.unrealengine.com/t/making-a-ufunction-that-calls-output-pin-multiple-times/1337087/7 "2023-11-18T03:09:54Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
