Download

How to bind to an event dispatcher declared in a BP?

Ok, so I hacked this to bind to MyDispatcher in Component (which is a BP component):



       UMulticastDelegateProperty* DelegateProp = FindField<UMulticastDelegateProperty>(Component->GetClass(), FName(TEXT("MyDispatcher")));
       FMulticastScriptDelegate* Delegate = DelegateProp->GetPropertyValuePtr_InContainer(Component);
       OnUnitHealthChangedDelegate.BindUFunction(this, FName(TEXT("MyFunction")));
       Delegate->Add(MyDelegate);


in the class definition:



       FScriptDelegate MyDelegate;

       UFUNCTION(BlueprintCallable)
       void MyFunction(float Param1, AActor* Param2);


And the binding goes ok, and MyFunction is called when needed, but the parameter values are invalid and this == nullptr.
I guess MyFunction should have signature tailored for FScriptDelegate - but what should it be?
I looked into code of a nativized BP that binds to the dispatcher but can’t get any sense of it :slight_smile: