The code below binds a function into delegate DelegatePropertyName
in SourceActor
. The bound function is in TargetActor
, with name HandleFunctionName
.
//Look up the delegate property (dynamic multicast or BP-created event dispatcher)
auto* DelegateProp = FindFProperty<FMulticastDelegateProperty>(SourceActor->GetClass(), DelegatePropertyName);
if(DelegateProp)
{
//Look up the function we want to be called by the delegate
UFunction* Func = TargetActor->GetClass()->FindFunctionByName(HandleFunctionName);
//We shouldn't bind it unless it matches the signature
if(Func && Func->IsSignatureCompatibleWith(DelegateProp->SignatureFunction))
{
FScriptDelegate ScriptDelegate;
ScriptDelegate.BindUFunction(TargetActor, HandleFunctionName);
DelegateProp->AddDelegate(ScriptDelegate, SourceActor);
}
}