Binds a given callback function to the specified topic(s). The callback will be executed upon any object sending event with matching topic.
There are three ways to subscribe:
Subscribe to single topic with delegate
Subscribe to all topics with delegate
Subscribe to all topics as an interface implementer
Single object can subscribe multiple times to multiple topics using single or many callback functions. There is virtually no limitation other than your sanity.
The callback function must take in two parameters: Topic of type FGameplayTag and Payload of type UObject*, and have no return type (void).
Single topic with delegate
Achieved by calling SubscribeToTopic function and providing the callback function. The function returns a handle to the created binding.
Callback has to be bound to UObject that represents callback's lifetime scope. If you bind simple lambda or a static function, the cleanup won't be able to remove the entry from the invocation list.
All topics with delegate
Achieved by calling SubscribeToAllTopics function and providing the callback function. This allows to have a single handler for all topics. This is great for "catch 'em all" scenario or when need to filter/decide which events to respond to at runtime.
Callback has to be bound to UObject that represents callback's lifetime scope. If you bind simple lambda or a static function, the cleanup won't be able to remove the entry from the invocation list.
All topics as an interface implementer
Achieved by calling SubscribeToAllTopicsAsInterface function. The caller has to implement IDispatchitoSubscriberInterface which provides the OnEvent function acting as a callback.
Define class implementing the interface:
UCLASS()
class USubscriberWithInterface : public UObject, public IDispatchitoSubscriberInterface
{
GENERATED_BODY()
public:
virtual void OnEvent_Implementation(FGameplayTag Tag, UObject* Payload) override
{
// event handling logic
}
};