# I don't get how Delegates / Events works on Unreal Engine

**URL:** <https://forums.unrealengine.com/t/i-dont-get-how-delegates-events-works-on-unreal-engine/2006257>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, Event, delegates, CPP, Blueprint, question\
**Created:** [September 5, 2024, 10:24am UTC](https://forums.unrealengine.com/t/i-dont-get-how-delegates-events-works-on-unreal-engine/2006257 "2024-09-05T10:24:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Untiziotizio](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Untiziotizio](https://forums.unrealengine.com/u/Untiziotizio)\
**Post date:** [September 5, 2024, 10:24am UTC](https://forums.unrealengine.com/t/i-dont-get-how-delegates-events-works-on-unreal-engine/2006257/1 "2024-09-05T10:24:03Z")

</div>

Hi, please help me.  
I’ve already posted another question on [StackOverflow](https://stackoverflow.com/questions/78903588/ue5-c-event-doesnt-fire) and here in the [Unreal Engine Forum](https://forums.unrealengine.com/t/ue5-c-event-doesnt-fire/1988720) about a specific problem that I currently have in my project, but nobody seems to reply.

So I’ll resume this shortly: I wanna make an HealthComponent (a C++ class) for my character, and also display the HP with an HealthBar Widget Blueprint.

Now I’m not a big fan of Copuling classes together, so I always use Events in these cases. The thing is that the delegate I’m trying to fire up (in my case **OnHealthSet** ) seems not to work. Whenever I call the:

```auto
OnSetHealth.Broadcast(MaxHealth, CurrentHealth);

```

nothing happens. I don’t get if I’ve missed some steps in order to make this work. I’m used to Unity events since I’ve been using it for 3 years, but in Unreal Engine this seems too convoluted.

This is the HealthComponent.h file:

```auto
#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "HealthComponent.generated.h"

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class RPG_TEST_API UHealthComponent : public UActorComponent
{
	GENERATED_BODY()

public:	

	UHealthComponent();

	DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(
		FOnSetHealth,
		float, MaxValue,
		float, CurrentValue
	);
	UPROPERTY(BlueprintAssignable) FOnSetHealth OnSetHealth;

	UFUNCTION(BlueprintCallable) int GetHealth() { return CurrentHealth; } 
	UFUNCTION() void SetHealth(const int Value);

protected:
	
	virtual void BeginPlay() override;

private:	
	
	UPROPERTY(EditAnywhere) unsigned int MaxHealth;
	UPROPERTY(EditAnywhere) unsigned int CurrentHealth;

};

```

While this is the HealthComponent.cpp file:

```auto
#include "HealthComponent.h"

// Sets default values for this component's properties
UHealthComponent::UHealthComponent()
{

}

void UHealthComponent::BeginPlay()
{
	Super::BeginPlay();

	SetHealth(MaxHealth);
}

void UHealthComponent::SetHealth(const int Value)
{
	CurrentHealth = (Value < 0) ? 0 : Value;
	CurrentHealth = (Value > (int)MaxHealth) ? MaxHealth : Value;
	
	OnSetHealth.Broadcast(MaxHealth, CurrentHealth);
}

```

And this is the HealthBar Blueprint which I’m trying to subscribe to the event:

 ![Screenshot 2024-08-22 223019](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/e/4/5e4567f6fe6b42313a899f67a352d2a920343f36.png)

---

<div class="post-metadata">

**Author:** ![Arodi007](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arodi007/32/1022275_2.png) [@Arodi007](https://forums.unrealengine.com/u/Arodi007)\
**Post date:** [September 5, 2024, 11:06am UTC](https://forums.unrealengine.com/t/i-dont-get-how-delegates-events-works-on-unreal-engine/2006257/2 "2024-09-05T11:06:04Z")

</div>

If it an event dispatcher, it will need binding.

If it just a custom event(the one in red represent create), you will to call it (in blue).

So it will depend how you bind the event or how you are calling the custom event “OnSetHealth”

---

<div class="post-metadata">

**Author:** ![zeaf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zeaf/32/1108035_2.png) [@zeaf](https://forums.unrealengine.com/u/zeaf)\
**Post date:** [September 5, 2024, 5:37pm UTC](https://forums.unrealengine.com/t/i-dont-get-how-delegates-events-works-on-unreal-engine/2006257/3 "2024-09-05T17:37:43Z")

</div>

Like @Arodi007 said, you have to bind an event to the delegate  
In blueprint this is done by dragging from an object reference and using the Bind/Assign to Event options

For example in your case, you can drag from the health component after setting it, and search for `Assign Event to OnSetHealth`, which will automatically create a bind node, and a new event with the same signature that will be bound to the delegate

---

<div class="post-metadata">

**Author:** ![Untiziotizio](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Untiziotizio](https://forums.unrealengine.com/u/Untiziotizio)\
**Post date:** [September 5, 2024, 7:31pm UTC](https://forums.unrealengine.com/t/i-dont-get-how-delegates-events-works-on-unreal-engine/2006257/4 "2024-09-05T19:31:26Z")

</div>

![Screenshot 2024-09-05 212714](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/b/e/0bed3c0cb4a54e8f92491e8489cfa1d5298879d6.png)  
I think this should be your solution. The fact is that I’ve already done that but still this doesn’t work. I think the real problem is the

```auto
OnSetHealth.Broadcast(MaxHealth, CurrentHealth);

```

instruction in the cpp file, because I’ve also tried to subscribe a simple function to the delegate and it didn’t do anything

---

<div class="post-metadata">

**Author:** ![zeaf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zeaf/32/1108035_2.png) [@zeaf](https://forums.unrealengine.com/u/zeaf)\
**Post date:** [September 5, 2024, 8:32pm UTC](https://forums.unrealengine.com/t/i-dont-get-how-delegates-events-works-on-unreal-engine/2006257/5 "2024-09-05T20:32:53Z")

</div>

no that is correct  
Unless you’re calling set health in other places, begin play has most likely already run by the time you bind the event in the widget, which would explain why you don’t get the callback

You can place a breakpoint on the broadcast line and see through the debugger what is bound to your delegate. If you don’t see any function in the invocation list that means that nothing been bound.

---

<div class="post-metadata">

**Author:** ![Untiziotizio](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Untiziotizio](https://forums.unrealengine.com/u/Untiziotizio)\
**Post date:** [September 5, 2024, 9:18pm UTC](https://forums.unrealengine.com/t/i-dont-get-how-delegates-events-works-on-unreal-engine/2006257/6 "2024-09-05T21:18:05Z")

</div>

Well I also putted the broadcast instruction in the Tick function to check what would happen, but nothing
