It can be done with C++
The Lyra Team Agent Interface is doing something similar with the OnTeamChangedDelegate, and you can probably take it one step further and expose it to blueprint. But I don’t think it’s possible at all in BP.
You would just need to declare a delegate
DECLARE_DYNAMIC_DELEGATE(FMyDelegate);
And then in your interface create a function like so:
UFUNCTION(BlueprintCallable)
virtual void MyFunction(const FMyDelegate& MyDelegate);
Then in your implementing classes you could have a field for that delegate:
FMyDelegate MyObjectsDelegate;
And implement the function:
void MyFunction(const FMyDelegate& MyDelegate) override
{
MyObjectsDelegate = MyDelegate;
};
And then somewhere else in your object you’d do:
void MyDelegateBroadcastingFunction()
{
MyObjectsDelegate.ExecuteIfBound();
};
This has one quirk, which is that it can’t be bound to multiple functions at once, so you can have only one listener
But I think you can combine it with a multicast delegate, and bind the delegate from your function argument to the multicast
DECLARE_DYNAMIC_DELEGATE(FMyDelegate);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FMyDelegateMulticast);
...
UFUNCTION(BlueprintAssignable)
FMyDelegateMulticast MyMulticastDelegateProperty;
void MyFunction(const FMyDelegate& MyDelegate) override
{
MyMulticastDelegateProperty.AddUnique(MyDelegate);
}
I suppose you can also have the delegate be part of the interface (similar to the LyraTeamAgentInterface):
virtual FMyDelegateMulticast* GetMyMulticastDelegate() { return nullptr; }
FMyDelegateMulticast& GetMyMulticastDelegateChecked()
{
FMyDelegateMulticast* MyDelegate = GetMyMulticastDelegate();
check(MyDelegate);
return *MyDelegate;
}
And then combine everything together:
// This can now be your interface function, probably should not be virtual
void MyFunction(const FMyDelegate& MyDelegate)
{
GetMyMulticastDelegateChecked().AddUnique(MyDelegate);
}
And in your implementing class you add a FMyMulticastDelegate Property, override the GetMyMulticastDelegate() function to return the property, and that should be all
Disclaimer, I wrote this code in this reply box, so it’s not fully tested, but I have done this exact thing before and it should work