Exposing event for both C++ and Blueprint

Hi,

I’m wondering is there a good way for my c++ class to provide a unified event-like API for both c++ classes and blueprints.

Example: I have ACannon class and I want to define OnFire member that both classes and blueprints can bind to.

For other classes - I can use a dynamic delegate as described here: https://docs.unrealengine.com/en-us/…legates/Events and this way I’m able to bind multiple c++ methods/functions to OnFire.

For blueprints - I can use either BlueprintNativeEvent or BlueprintImplementableEvent in UFUNCTION, and then I’m able to bind multiple behaviours to OnFire in any number of blueprint graphs.

Unfortunately, I cannot combine the two mentioned solutions. That is: I cannot apply the UFUNCTION to the dynamic delegate. It seems that for each event (like OnFire) I need to define two separate class members - one for c++ and another for blueprints.

Is there a way to provide an event for c++ and blueprint using a single class member?

Regards!

EDIT:
I found that the BlueprintAssignable UPROPERTY specifier almost does what I want. Except it only works for multicast-delegates, and not for events. Is there any way to expose an event to blueprints?

You ever figure out the answer? I’m trying to figure the exact same thing out right now. I’m guessing the solution is just to use a dynamic multicast delegate instead, because maybe events don’t support working this way, but I’m hoping I’m wrong.

I gues what you are looking for are
dynamic delegates. Dynamic allows for blueprint and cpp binding, but only one listener. If you need more listener you need dynamic multicast delegate.

DECLARE_DYNAMIC_MULTICAST_DELEGATE…(FYourDelegate, …)

in class
UPROPERTY(BlueprintAssignable, …)
FYourDelegate delegateVariableName;

2 Likes

Sadly Events are not supported.
That’s a shame, because the Delegate can be thrown by other class than itself (main difference between event and delegate). I don’t know if it a technical limitation or just by design.

If you use UPROPERTY(BlueprintNativeEvent) you can implement it in C++ an override in Blueprint

Sadly no.
If you do that you can’t bind another BP class on this event to react.
You can only react to it in a BP derived class but that’s not what Elgcahlxukuth wants. Or I misunderstand it.

Actually its quite confusing what he actually wants.