Search code examples
c++unreal-engine4unreal-blueprint

C++ equivalent blueprint event dispatcher vs blueprint events


I know delegates are the equivalent to dispatchers. But there are so many different types of event declarations. Using the UFUNCTION macro events can be defined using BlueprintNativeEvents and BlueprintImplementableEvent. But then there is DECLARE_EVENT macro. I love to overthink things. can someone explain the difference between dispatchers, events, and the various types of events? Are dispatchers the observable and events the observers to those observables in the observer pattern?


Solution

  • When you use UFUNCTIONs BlueprintNativeEvent and BlueprintImplementableEvent - it means that this function can be overriten by a Blueprint. Then you can launch a blueprint function from c++.

    Then - there are several types of delegates:

    DECLARE_DELEGATE - C++ only, standard delegate, only one function can bind to it.

    DECLARE_MULTICAST_DELEGATE - C++ only just like standard delegate but multiple functions can bind to it an be called all at once using Broadcast function.

    DECLARE_EVENT - C++ only. Just like a multicast delegate but only the owner of this event can call a Broadcast.

    DECLARE_DYNAMIC_MULTICAST_DELEGATE - C++/BP. It's like a multicast delegate, but it is serializable and can be bindable from blueprints when you use BlueprintAssignable keyword in UPROPERTY.

    Event Dispatcher are a BP only equivalents of DYNAMIC_MULTICAST_DELEGATE I think. You can bind multiple events to it and broadcast them at once.