For dynamic delegates there is a macro named AddDynamic
with params ContextObject
(usually passing this
) & UFunction pointer
(usually passed like &ASomeClass::OnSomeFunction
as said in other comment)
But. If your delegate need no being exposed to bp, then it’s better to use native (non-dynamic) delegates, as they have way more ways to interact with cpp. So your code will looks like:
//header
DECLARE_MULTICAST_DELEGATE_OneParam(FMsgDispatcherNative, const struct FRecvContext&);
UClass
class UXXComponent: : public UActorComponent
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintAssignable)
FMsgDispatcherNative OnRecvMsg;
}
//cpp
void UXXComponent::someFunction()
{
OnRecvMsg.AddLambda([](const struct FRecvContext& Context){
//some actions with `Context`
});
FRecvContext Context = ... ;
OnRecvMsg.Broadcast(Context);
}
If you need both types of delegates then usually i’m define both types and call broadcasts next to each other