Using delegates as function parameters

From the Blueprint Node CreateEvent I receive a Delegate object as output parameter. Now I want to use that delegate as parameter for custom function. However, when defining the paramters for that function, I am not able to select Delegate as parameter type.

How can I use a previously created Delegate object as parameter for a Blueprint function?

You cannot use delegates as function parameters, as delegates are not valid variable types as inputs. However, you can use delegates as inputs to a macro by using the wildcard variable.

Thanks for your quick reply. So you’re right, Macros would work here. Unfortunately in my case Macros are not an option, since I need to bind to an event dispatcher from within the Macro/Function, using the “Bind Event to …” BP node. This node cannot be used in a Macro.

Any ideas how I could work around that problem?

Store a reference to that Object maybe? That way you can bind and unbind to its Event Delegates all you like.

Apparently I cannot do that from within a Macro :frowning:

Why are you trying to Bind to an Event within a Macro?

Store the reference as a Variable that is part of the BP then you can access its Event Delegates within that BP.

I don’t. What I am trying to do is to call the “Bind to …” BP node from within a Macro.
Which apparently is not possible.

i was able to take delegates in blueprint functions,
but oddly enough only when i created them by collapse to function,
not when i set up all inputs by hand

the delegate input param is not listed as option when i set types by hand…

1 Like

You can add delegate parameter to function by dragging event pin from event dispatcher and dropping it on the function.


9 Likes

probably you re looking for event dispatchers. check this out Event Dispatchers / Delegates Quick Start Guide | Unreal Engine 4.27 Documentation.

It makes no sense why this requires such a hacky unintuitive solution. And it’s only half of a solution, really, e.g. what if I wanted to create an interface that accepts a delegate parameter?

I know, probably there are some kind of limitations :man_shrugging:

I agree with Mad.King about this being a ridiculous workaround, but you just blew my mind with this post and I will be using this many times. Thank you!!!

You can make an interface with a delegate parameter. It’s wacky but once you got a function with a delegate parameter in a blueprint, you can simply copy it from the BP’s functions list and paste it in your Interface’s functions list. Just be sure to paste an empty function or you’ll get a compilation error.

DISCLAIMER : This is wacky on purpose. Delegates are dangerous objects if incorrectly handled. It can crash at cooking, crash the game if the delegate’s owner is destroyed, create memory leaks, and if bad luck, it can corrupt .uassets.
Use it for small systems, client only, not interacting with multiplayer. Do not build an entire complex system around it, take notes of everywhere you use a delegate parameter, and make extensive testing.
In the best practice, you should use C++ for passing delegates.

Anyway, here, we ball. Here is the way :

  1. available function in another BP, with the delegate parameter made by dragging a delegate node to the function’s input node

  1. pasted and renamed function in the Blueprint Interface