Throwing an Event in C++ and reacting to that event using Blueprints

Hey all, Im currently trying to throw an Event in a custom cpp and listen to that event in a blueprint.
My current use case for this would be my health bars. I want to have multiple health bars that can be refilled on their own.

I already have taking damage to the players health and regenerating it nailed down (Im overriding the standard TakeDamage function for taking Damage and I’ve written a custom heal function). but I just cant figure out how to listen to the changes in Health.

I have already tried creating an event like this


DECLARE_DYNAMIC_MULTICAST_DELEGATE_FiveParams(
  FOnHealthChanged, // Name of the structure that will be generated
  AActor*, Instigator, // Who caused the health change
  UCurrentHealthComponent*, ChangedComponent, // Component that called the event
  float, NewValue, // New health value
  float, OldValue, // Old health value
  bool, OverKill // If damage value was higher than health value
);

and exposing the event of that Healthcomponent to Blueprints like this

UPROPERTY(BlueprintCallable)
FOnHealthChanged OnHealthChanged;

I am then broadcasting my event in my cpp like this

OnHealthChangedEvent.Broadcast(EventInstigator, this,this->Value, originalValue, isOverkill)

But In my Blueprint editor, I cannot drag a node relating to my FOnHealthChanged event. Is there something Im missing?

You need to add BlueprintAssignable to be able to bind to delegates in Blueprints.

UPROPERTY(BlueprintAssignable)
FOnHealthChanged OnHealthChanged;

Thank you for the quick answer, I tried that, but I cannot bind a new event to that call
image

And clicking Create Event results in this:

Does this not work? That’s how it’s done usually.

In the Create Event node, you can click the Select Function drop down and there should be an option to Create a Matching function or Event.

I hadnt noticed the Create Matching Event button in the dropdown, thank you very much :smiley:

1 Like

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