How to bind delegate inside blueprint functions

Hi guys,

I have a problem with my blueprint. It’s created from a C++ class where I have created this delegate :

Then delcared like that :
image

And then I have this function in my blueprint :


Where I bind the delegate to an event, which can be custom that’s why I put it in a function.

However when I try to compile the BP i Get this :

The current value of the ’ Event ’ pin is invalid: ‘Event’ in action ‘Add Tag Listener BP’ must have an input wired into it (“by ref” params expect a valid input to operate on).

Any ideas on how to do this ?

Thanks

When you call this function, you need to bind an event to the delegate:
image

1 Like

I precisely want to let that Custom Event be defined when the function is called on the actor on which the actor component is attached. If i do this I won’t be able to change what’s in the CustomEvent.

What’s in the custom event is defined by the delegate, you can’t have different types of events connected to the same delegate.

1 Like

In that case is it possible to pass a delegate as an argument of a c++ function (with the same signature of course)?

I’m not sure. I’ve just tried declaring a delegate as pointer, but it crashes the engine when playing, but maybe I’m doing something wrong.

If I declare the delegate in a regular way, I can send it as an argument, but that sends a copy, so it doesn’t really work, because you’re not binding to the delegate that’s being broadcast.

You can create a function in a function library, e.g. :

And then call it from anywhere:
image

But the custom event must be the same.

Are you trying to create one massive delegate with a lot of arguments, so that different actors would bind to the same even, but use different arguments? Or what is the purpose?

Basically I have a c++ class called “GameplayTagsManager” where I have 2 variables called ActiveTags(GameplayTagContainer) and ActiveTagsStacks(TMap Fname int32). The purpose of this actor component is to manage the add and removal of gameplay tags of the actor it is attached to. So other actor can add or remove tags from it, and some of them may need to know when particular tags are added or removed from the actor. For example I have a character, and an annemy spawn a poison Status effect actor on the character, damage are going to be applied to the character but if I have a gameplaytag on my character called let’s say “poison immunity” then the Poison actor needs to know if this tag is applied and when it’s added or removed. Then I can use that custom event to decide wheter I should apply or not damage to the actor and implement the logic in that custom event.