# Delegates as Parameter

**URL:** <https://forums.unrealengine.com/t/delegates-as-parameter/299175>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [November 17, 2014, 1:14pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175 "2014-11-17T13:14:31Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruohki](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ruohki](https://forums.unrealengine.com/u/ruohki)\
**Post date:** [November 17, 2014, 1:14pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/1 "2014-11-17T13:14:31Z")

</div>

Hello, iam working on a Userinterface in Blueprint and have a hard time dealing with callbacks of buttons etc.

Is there any easy way to supply a delegate reference to a function via a parameter or any way to give my function something so i can bind events in that function?

---

<div class="post-metadata">

**Author:** ![Asher\_S\_Einhorn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Asher\_S\_Einhorn](https://forums.unrealengine.com/u/Asher_S_Einhorn)\
**Post date:** [December 26, 2014, 11:51am UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/2 "2014-12-26T11:51:19Z")

</div>

It’s funny how there are some completely dead topics on this site isn’t it? I can never get anyone to give me answers related to either delegates or animation.

---

<div class="post-metadata">

**Author:** ![ruohki](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ruohki](https://forums.unrealengine.com/u/ruohki)\
**Post date:** [December 26, 2014, 12:46pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/3 "2014-12-26T12:46:19Z")

</div>

yeh this sucks the way delegates are right now is completely useless 😕 ill try and get this working in c++ maybe i can add a delegate reference datatype or whatever

---

<div class="post-metadata">

**Author:** ![Asher\_S\_Einhorn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Asher\_S\_Einhorn](https://forums.unrealengine.com/u/Asher_S_Einhorn)\
**Post date:** [December 26, 2014, 1:09pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/4 "2014-12-26T13:09:40Z")

</div>

not true, you can create an event dispatcher and bind to that.

---

<div class="post-metadata">

**Author:** ![Asher\_S\_Einhorn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Asher\_S\_Einhorn](https://forums.unrealengine.com/u/Asher_S_Einhorn)\
**Post date:** [December 26, 2014, 1:12pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/5 "2014-12-26T13:12:45Z")

</div>

You need to create an event dispatcher as the ‘variable’ you will store your function in. This is what you will call. Then, in the other class you create a custom event with the same signature you want to be called. get a handle to the first class and find the ‘bind to event x’ option. then pipe the delegate handle from the custom event into the bind node.

now when you call your function the custom event will be called instead.

---

<div class="post-metadata">

**Author:** ![Asher\_S\_Einhorn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Asher\_S\_Einhorn](https://forums.unrealengine.com/u/Asher_S_Einhorn)\
**Post date:** [December 26, 2014, 1:13pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/6 "2014-12-26T13:13:18Z")

</div>

you can do it in blueprints. see my answer below.

---

<div class="post-metadata">

**Author:** ![RAVaught](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RAVaught](https://forums.unrealengine.com/u/RAVaught)\
**Post date:** [December 27, 2014, 5:39pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/7 "2014-12-27T17:39:47Z")

</div>

Well, there is a way, and it is actually not that difficult. If you have a set list of functions that you are choosing from, and suspect you do, here is the way I would handle it.

1. On the event host, create all of your events.
2. Create event dispatchers for each event and bind them. You will likely need to do that event binding either in the construction script or in the event begin play script.
3. Create the function you want to call, let it take an int (or enum) as input
4. Inside the function, use a switch on int to send call the correct event dispatcher.

You can even use variations on this to bind/unbind events from event dispatchers and such. Up to you.

Tony

---

<div class="post-metadata">

**Author:** ![itsAcren](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/itsacren/32/1194653_2.png) [@itsAcren](https://forums.unrealengine.com/u/itsAcren)\
**Post date:** [August 18, 2015, 4:22am UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/8 "2015-08-18T04:22:03Z")

</div>

What if I don’t want to store the function, and just want to pass it into another function which calls it, calculates things and returns without storing it?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5955ea44](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5955ea44](https://forums.unrealengine.com/u/anonymous_user_5955ea44)\
**Post date:** [September 23, 2015, 5:17am UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/9 "2015-09-23T05:17:57Z")

</div>

That’s not actually answering the question, that’s called making a work-around.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5955ea44](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5955ea44](https://forums.unrealengine.com/u/anonymous_user_5955ea44)\
**Post date:** [September 23, 2015, 5:19am UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/10 "2015-09-23T05:19:21Z")

</div>

I agree, this is what I need.

---

<div class="post-metadata">

**Author:** ![manoelneto](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@manoelneto](https://forums.unrealengine.com/u/manoelneto)\
**Post date:** [November 20, 2015, 7:12pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/11 "2015-11-20T19:12:24Z")

</div>

Yes, but you can’t do it using only blueprints: only functions created in C++ can accept delegate parameters. Blueprints can only create event dispatchers, which are multicast delegates.

For UI, you create a dispatcher in your custom widget blueprint. Then when you add that widget component to another widget, you can bind the events directly from the design view, just as you do with the built-in button component: your dispatchers are listed at the bottom of the details panel, with buttons that will create the event nodes for you.

---

<div class="post-metadata">

**Author:** ![Lweniel](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lweniel](https://forums.unrealengine.com/u/Lweniel)\
**Post date:** [April 13, 2016, 11:06am UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/12 "2016-04-13T11:06:12Z")

</div>

Can you comment on how it would look in C++ (snippets of source code perhaps)? Thanks!

---

<div class="post-metadata">

**Author:** ![manoelneto](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@manoelneto](https://forums.unrealengine.com/u/manoelneto)\
**Post date:** [April 14, 2016, 6:58pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/13 "2016-04-14T18:58:04Z")

</div>

Sure, here’s some snippets from our project:

Declaring the delegate type:

```
DECLARE_DYNAMIC_DELEGATE_OneParam(FOnlineUserImageRetrievedDelegate, UTexture2D*, Texture);

```

Declaring a method that takes the delegate as a parameter:

```
/* Retrieves the user thumbnail texture*/
UFUNCTION(BlueprintCallable, Category = OnlineUser)
void RetrieveThumbnail(const FOnlineUserImageRetrievedDelegate& Callback);

```

Declaring a variable to store the delegate:

```
FOnlineUserImageRetrievedDelegate ImageRetrievedDelegate;

```

The implementation does something like this:

```
void UOnlineUser::RetrieveThumbnail(const FOnlineUserImageRetrievedDelegate& Callback)
{
    ImageRetrievedDelegate = Callback;
}

```

And to call the delegate something like this:

```
ImageRetrievedDelegate.ExecuteIfBound(ThumbnailTexture);

```

And it looks like this in the blueprint:

![86888-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/e/9/7e92c63b537f23ccbb653a1afc32b5ef490bc215.png)

---

<div class="post-metadata">

**Author:** ![jdannenbring](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jdannenbring](https://forums.unrealengine.com/u/jdannenbring)\
**Post date:** [September 12, 2016, 5:56pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/14 "2016-09-12T17:56:02Z")

</div>

I read through this and ended up using interfaces to implement a callback mechanism similar to passing a delegate.  
You can view my workaround here: [Building New Worlds - Nose to the Grindstone](http://bit.ly/2cj6YLu)

---

<div class="post-metadata">

**Author:** ![alonecat06](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@alonecat06](https://forums.unrealengine.com/u/alonecat06)\
**Post date:** [November 20, 2016, 2:25pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/15 "2016-11-20T14:25:21Z")

</div>

I follow your code, but vs report an error said, Unrecognized type ‘FOnlineUserImageRetrievedDelegate’ - type must be a UCLASS, USTRUCT or UENUM.  
When I remove the decoration(‘UFUNCTION(BlueprintCallable, Category = OnlineUser)’) above the function RetrieveThumbnail, the project can compile and no error.  
I wonder how can you compile those code withour error

---

<div class="post-metadata">

**Author:** ![Elathan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Elathan](https://forums.unrealengine.com/u/Elathan)\
**Post date:** [April 19, 2017, 5:37pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/16 "2017-04-19T17:37:59Z")

</div>

I have the same problem… any solution?

---

<div class="post-metadata">

**Author:** ![Elathan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Elathan](https://forums.unrealengine.com/u/Elathan)\
**Post date:** [April 19, 2017, 6:27pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/17 "2017-04-19T18:27:43Z")

</div>

I messed up with the macros.  
Solution:  
DECLARE\_DYNAMIC\_DELEGATE for the function parameter.  
DECLARE\_DYNAMIC\_MULTICAST\_DELEGATE for the class variable.

Handle isn’t needed (isn’t even there iirc), same event input param can be used to unsubscribe.

Kinda cool and everything seems to work, if I have the time I am going to make a tutorial on this.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0792572e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0792572e](https://forums.unrealengine.com/u/anonymous_user_0792572e)\
**Post date:** [December 13, 2017, 6:47pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/18 "2017-12-13T18:47:59Z")

</div>

tell me about it, it’s like nobody uses unreal or at least this forum, but it’s the same at other forums, barely an answer from time to time

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0792572e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0792572e](https://forums.unrealengine.com/u/anonymous_user_0792572e)\
**Post date:** [December 13, 2017, 6:50pm UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/19 "2017-12-13T18:50:29Z")

</div>

why are they called event dispatcher since one sets them up to receive events as far as I nderstand  
[edit:jeee this forum sucks to reply to the right person]

---

<div class="post-metadata">

**Author:** ![PhoenixMarket](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/phoenixmarket/32/980948_2.png) [@PhoenixMarket](https://forums.unrealengine.com/u/PhoenixMarket)\
**Post date:** [October 31, 2018, 8:03am UTC](https://forums.unrealengine.com/t/delegates-as-parameter/299175/20 "2018-10-31T08:03:26Z")

</div>

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

 ![258154-delegateparameter.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/3/9/b39254b20747f93f86ece0b70b86b9f9e06ff8f8.png)

 ![258155-delegate.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/e/5/2e5f4841fd25061e555e22899693eb111cc523c7.png)

[Next page](https://forums.unrealengine.com/t/delegates-as-parameter/299175.md?page=2)
