Binding blueprint method/event to C++ delegate

Hey guys,

the case here is, I want to give blueprint designers a possibility to connect a method to my C++ component, which will invoke that specific method in a certain moment. I’m out of ideas how it could be implemented, so I’d appreciate any help.

It’s already done within Unreal Blueprint Editor in a dispatcher system, so let me illustrate it by this screenshot:

116324-1.png

Now, I have a C++ class inheriting from ActorComponent, above which I’m declaring some kind of delegate (for example multicast) and I have a method inside that C++ class, named AddMethodCallback().

I want AddMethodCallback, to have an argument to pass the function so I could bind it’s address to my delegate. AddMethodCallback would be a BlueprintCallable and I just don’t know how to declare the argument so it would appear in Editor just like on the screenshot.

I know how to declare other types of inputs and outputs, just not this one “Event input type”. Any ideas?

BTW.
2nd question:
I didn’t use dispatchers too much, could you explain me the outcome here, related to the first screenshot?

2 Likes

In case you haven’t solved this, or for others reference - you need to ensure the delegate in your C++ component has the UPROPERTY set to BlueprintAssignable.

You should have your delegate declared as DYNAMIC_MULTICAST somewhere and have a variable defined in the component like in the following example:

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FExampleDelegate_OnSomething, float, _exampleEventParameter);

UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class YOURPROJECTNAME_API UComponentExample : public UActorComponent
{
    GENERATED_BODY()

public:
    UPROPERTY(BlueprintAssignable)
        FExampleDelegate_OnSomething ExampleDelegateVariable;
}

To access this in a Blueprint, get the component reference in the Event Graph and pull off of it to create a node, this will allow you to create a node to - assign to the delegate; bind an event to the delegate; call the delegate; unbind event(s) from the delegate.

11 Likes

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