# \[Tutorial\] Creating and Using Delegates C++ and Accessing them in Blueprints

**URL:** <https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [August 18, 2014, 4:36pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649 "2014-08-18T16:36:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_6334e343](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6334e343](https://forums.unrealengine.com/u/anonymous_user_6334e343)\
**Post date:** [August 18, 2014, 4:36pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/1 "2014-08-18T16:36:45Z")

</div>

\*\*Before we start: \*\*  
A disclaimer I do not pretend to be an expert but i do my best in trying.  
So if any mistakes are made in this tutorial I please let me know so I can fix them that and feedback in general is much aprichiated.

**What will we learn in this tutorial:**  
In this tutorial you will learn how to create and use a delegate in Unreal Engine 4.  
And making them available in Blueprints.  
Using C++, i will try to keep this as explaining as i can leaving out any complicated examples or wall of code.

**What is a delegate?**  
A technical explanations is available on the Documentation. (See reference link at the bottom.)  
But broken down a delegate is a event that is Brodcasted / «Sendt» in your game.  
These can be picked up by other classes / Actor in your game, variables can also be included so you have a copy of the data.

Note: In this tutorial am using a copy of the value, i thought that made the code look simpler.  
But please note that you should pass any data with reference when possible to save memory.

**Now lets get coding:**

The first thing you want to do when creating a delegate is go to the header of the class you want the delegate to be Broadcasted from.

Over your class deceleration, you will want to declare your delegate.  
e.g: Over this.

```auto

/**
 * 
 */
UCLASS()
class YOUR_API AYourGameState : public AGameState
{
	GENERATED_UCLASS_BODY()

```

You do this by using the following macro.

```auto

DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FGameStateTimeOfDayChanged, float, Houer, int32, Minute, int32, Sec);

```

The above code declares a new delegate with the name and 3 parameters.  
The «FGameStateTimeOfDayChanged» is the delegate name «type» and the the following are the data types and there names devide by a comma «,».

e.g: You want to make a delegate to pick up a chat string from a team chat in-game, this would at least need 2 FString`s one for the player name that sendt the message. And one for the actual message sendt to the team in-game.

You would declare the following delegate.

```auto

DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FTeamMessageSendtDelegate, FString, PlayerName, FString, Message);

```

Notice: Make a note of that the end of the delegate declaration changed from \_ThreeParams to \_TwoParams For a full overview on all the variations check out links at the bottom, but it lets the engine know how many you/ it needs.

Now we have our delegate and there are only two things left to do for creating them.  
First we go and add a new member to your class, its worth to mention that delegates don’t belong to the class. So there is no reason for not using the same delegate in a second class as long as it has its own member in that class.

We declare the new member for the delegate like this.

```auto

public:
	UPROPERTY(BlueprintAssignable)
		FGameStateTimeOfDayChanged OnTimeUpdated;

```

The BlueprintAssignable is used, so that it can be used with Blueprints.  
Now the only thing left to do is to have the class Broadcast the delegate with the data.  
In your class at some point you want to tell some other class that something happend like in-game time was changed in your game state.

You «send» the event like this.

```auto

	// Broadcast Delegate 
	OnTimeUpdated.Broadcast(CurrentHouer, CurrentMinute, CurrentSeconds);

```

CurrentHouer, CurrentMinute, CurrentSecond are members in my game state class, that the delegate belongs to. And are of type float, int32 and int32 this is the dala values «sendt with the delegate».  
remember we used BlueprintAssignable with the member so we can use it with blueprints already.  
But maybe you want to use it in code as well so then we can do the following, for this last example i am using a delegate with only one value a float.

So in your «second» class that you want the delegate to be «picked up» you need to create a callback function for that so we create a new function in our second class.  
Important: Copy the signature perfectly and add that to the function deceleration.

For Visual Studio users, right click on the delegate in VS and select/ mark the delegate name «FDelegateName» and right click and press «Go to Definition» to jump to the delegate signature. Or by pressing «Ctrl+Alt+F12»  
 ![Untitled.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/0/0/100ac7bfbb5f288ae81768c9392858c35bd8f209.png)

e.g: OnMinuteUpdate declaration looks like this.

```auto

// Used for getting the Time of Day on the map Min(0.00), Max(23.59).
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FGameStateSigleTODChanged, float, Houer);

```

So in our «second class» we add a new function like this.

```auto

	UFUNCTION()
		void BindToDelegate(float houer);

```

Notice we have the same type and name from the delegate.  
Now all that is left is to bind the new callback function to the delegate.

```auto

YourGameState->OnMinuteUpdate.AddDynamic(this, &AYourGameMode::BindToDelegate);

```

You use this line of code for that, note that «YourGameState» is the game state of your game that has been cast to your game state. So that you can find the new delegate member, adding «binding», this function to the delegate can be done in several places but ::BeginPlay() is a easy place to bind the delegate as you know your actor is in the world by then.

**Blueprints:** The only thing you need to do to use this with Blueprints is get the class / object.  
Search up the name of the delegate and add it to the graph.

**Conclusion:** By now i hope you have a good understanding of delegates and know how to use them.  
And also how to make them available in blueprints.  
In a later tutorial we will look at how we can have these callback functions or delegates be replicated over the network for multiplayer games.

\*\*Reference: \*\*

> **[Delegates](https://docs.unrealengine.com/5.1/en-US/delegates-and-lamba-functions-in-unreal-engine/)**
>
> Data types that reference and execute member functions on C++ Objects

> **[Use of delegates in Blueprint and Network](https://forums.unrealengine.com/questions/81924/use-of-delegates-in-blueprint-and-network.html)**
>
> I made a new delegate, like this. DECLARE\_DYNAMIC\_MULTICAST\_DELEGATE\_ThreeParams(FGameStateTimeOfDayChanged, uint32, Houer, uint32, Minute, uint32, Sec); And then i added it to my class like this. UPROPERTY(BlueprintAssignable, Category = "Time Of...

> **[UFunctions](https://docs.unrealengine.com/5.1/en-US/ufunctions-in-unreal-engine/)**
>
> Reference for creating and implementing functions for gameplay Classes

> **[Properties](https://docs.unrealengine.com/5.1/en-US/unreal-engine-uproperties/)**
>
> Reference for creating and implementing properties for gameplay classes.

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

Please leave feedback, PDF download available .  
For reading on the go.

Best Regards.  
.

---

<div class="post-metadata">

**Author:** ![zazabar](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zazabar](https://forums.unrealengine.com/u/zazabar)\
**Post date:** [August 19, 2014, 10:01pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/2 "2014-08-19T22:01:41Z")

</div>

Not sure why no comments yet, but thanks for the excellent writeup =)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6334e343](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6334e343](https://forums.unrealengine.com/u/anonymous_user_6334e343)\
**Post date:** [August 19, 2014, 10:23pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/3 "2014-08-19T22:23:54Z")

</div>

> [@;121582](#):
>
> Not sure why no comments yet, but thanks for the excellent writeup =)

You are welcome :), glad someone liked it.

---

<div class="post-metadata">

**Author:** ![mindfane](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mindfane/32/710746_2.png) [@mindfane](https://forums.unrealengine.com/u/mindfane)\
**Post date:** [August 20, 2014, 3:41am UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/4 "2014-08-20T03:41:33Z")

</div>

Nice tutorial.

Very useful

With some cleaning up and formatting, I thnk you could post this in the tootorial wiki

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_673ab64d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_673ab64d](https://forums.unrealengine.com/u/anonymous_user_673ab64d)\
**Post date:** [August 20, 2014, 9:18pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/5 "2014-08-20T21:18:35Z")

</div>

Great tut. Keep up the good work.

Thanks.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6334e343](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6334e343](https://forums.unrealengine.com/u/anonymous_user_6334e343)\
**Post date:** [August 21, 2014, 12:19pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/6 "2014-08-21T12:19:48Z")

</div>

You are welcome glad you liked it.

> [@](#):
>
> Nice tutorial.
> 
> Very useful
> 
> With some cleaning up and formatting, I thnk you could post this in the tootorial wiki

Sure i never added anything to wiki before so i need to read up on that stuff.  
What parts should be cleaned up btw ? 🙂

---

<div class="post-metadata">

**Author:** ![bzxo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bzxo](https://forums.unrealengine.com/u/bzxo)\
**Post date:** [May 2, 2015, 2:08pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/7 "2015-05-02T14:08:46Z")

</div>

Hi! Thank you for this write-up 🙂

I’m trying to achieve this with the recently added FCalculateCustomPhysics delegate, which you can read about .

However I can’t get it to work (I’m basically trying to create a new Event Tick BP node only for physics sub-stepping). Any ideas?

Edit: I’m trying to do this with an extension of the actor class - I’m including “PhysicsEngine/BodyInstance.h” but I keep getting this error;  
_Unrecognized type ‘FCalculateCustomPhysics’_

Edit 2: After some researching - seems like getting a Blueprint to run in the physics thread isn’t doable?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_9cf15cf7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9cf15cf7](https://forums.unrealengine.com/u/anonymous_user_9cf15cf7)\
**Post date:** [July 3, 2015, 9:49am UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/8 "2015-07-03T09:49:43Z")

</div>

Hey.

Newbie to UE4 C++ API.

Could you please elaborate on "YourGameState’, How do i find a reference to it in \<\<second\>\> class.

Thank you,

Thnk

---

<div class="post-metadata">

**Author:** ![Antidamage](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/antidamage/32/918692_2.png) [@Antidamage](https://forums.unrealengine.com/u/Antidamage)\
**Post date:** [September 17, 2015, 2:42am UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/9 "2015-09-17T02:42:28Z")

</div>

To be honest I found this confusing. Often the main problem with code snippets is that they lack context - there’s no indication where things go, what requires declarations and where THEY go. I’m no closer to creating a delegate.

A good solution to this would be to upload a sample project. Looks like a dead thread though sadly.

---

<div class="post-metadata">

**Author:** ![asmrpuppy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@asmrpuppy](https://forums.unrealengine.com/u/asmrpuppy)\
**Post date:** [November 16, 2015, 9:49pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/10 "2015-11-16T21:49:04Z")

</div>

Yeah, I’ve found this really confusing.

You need to treat people almost like a compiler.

There’s just too much jumping around and stuff that is disconnected from eachother.

However it is the only tutorial out there for delegates, so I’m very grateful and working through it.

---

<div class="post-metadata">

**Author:** ![DonOstias](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DonOstias](https://forums.unrealengine.com/u/DonOstias)\
**Post date:** [November 19, 2015, 5:28pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/11 "2015-11-19T17:28:08Z")

</div>

I agree, it´s very confusing…  
you should clarify that a variable of type ‘FGameStateSigleTODChanged’ called '‘OnMinuteUpdate’ is being declared in ‘YourGameState’…

Totally agree with ‘There’s just too much jumping around and stuff that is disconnected from eachother.’

Thanks anyway 🙂

---

<div class="post-metadata">

**Author:** ![Sanzenin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sanzenin](https://forums.unrealengine.com/u/Sanzenin)\
**Post date:** [April 14, 2016, 9:35pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/12 "2016-04-14T21:35:48Z")

</div>

Any other good tutorial? i’m noob, and it still confusing me using delegate. ☹  
Thanks anyway! 🙂

---

<div class="post-metadata">

**Author:** ![mdonge](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mdonge](https://forums.unrealengine.com/u/mdonge)\
**Post date:** [May 20, 2016, 5:28pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/13 "2016-05-20T17:28:28Z")

</div>

Really nice tuto ! it’s really easier than trying with the unreal doc 😉

---

<div class="post-metadata">

**Author:** ![rise678487](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rise678487](https://forums.unrealengine.com/u/rise678487)\
**Post date:** [June 17, 2016, 3:02am UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/14 "2016-06-17T03:02:26Z")

</div>

thanks man…good to see your next tuts…

---

<div class="post-metadata">

**Author:** ![zezba9000](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zezba9000](https://forums.unrealengine.com/u/zezba9000)\
**Post date:** [October 18, 2016, 7:02pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/15 "2016-10-18T19:02:59Z")

</div>

What header files are required? Is this “#include “DelegateCombinations\_Variadics.h”” ?  
Where does “DECLARE\_DYNAMIC\_MULTICAST\_DELEGATE\_OneParam” get defined? Before the class or in the class?

Is there a in .h and .cpp file that show what is going on in context?

---

<div class="post-metadata">

**Author:** ![SaxonRah](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SaxonRah](https://forums.unrealengine.com/u/SaxonRah)\
**Post date:** [October 18, 2016, 7:05pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/16 "2016-10-18T19:05:04Z")

</div>

Just an fyi, you might want to correct the line,

> [@](#):
>
> Note: In this tutorial am using a copy of the value, i thought that made the code look simpler.  
> But please note that you should pass any data with reference when possible to save memory.

to

> [@](#):
>
> Note: In this tutorial am using a copy of the value, i thought that made the code look simpler.  
> But please note that you should pass any data that isn’t going to be modified with a const reference when possible to save memory.

Edit oops, too quick to submit.  
Good job, though.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7c428589](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7c428589](https://forums.unrealengine.com/u/anonymous_user_7c428589)\
**Post date:** [January 8, 2017, 2:47am UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/17 "2017-01-08T02:47:27Z")

</div>

A couple people have commented that this wasn’t clear enough.  
I found a VERY thorough tutorial on Youtube if anyone is interested:

---

<div class="post-metadata">

**Author:** ![eyosido](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eyosido](https://forums.unrealengine.com/u/eyosido)\
**Post date:** [June 4, 2017, 4:00pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/18 "2017-06-04T16:00:53Z")

</div>

Interesting thread as a complement : [What difference between delegates? - Programming & Scripting - Unreal Engine Forums](https://answers.unrealengine.com/questions/533323/what-difference-between-delegates.html)

---

<div class="post-metadata">

**Author:** ![LIUC\_LT](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LIUC\_LT](https://forums.unrealengine.com/u/LIUC_LT)\
**Post date:** [November 21, 2017, 9:40pm UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/19 "2017-11-21T21:40:29Z")

</div>

**Thank You very much for best explanation about Delegates**

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_984cd5f0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_984cd5f0](https://forums.unrealengine.com/u/anonymous_user_984cd5f0)\
**Post date:** [September 4, 2018, 7:54am UTC](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649/20 "2018-09-04T07:54:36Z")

</div>

Thank you! This was really helpful! Awesome explanation! 🙂

[Next page](https://forums.unrealengine.com/t/tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints/9649.md?page=2)
