Events in Unreal Engine

Published on

What events are available in Unreal Engine and how to use them?

Platforma

Event Dispatcher

Source: Alex Quevillon - How To Create Event Dispatcher With C++

#include "Kismet/BlueprintFunctionLibrary.h" // Engine
#include "Delegates/DelegateCombinations.h" // Core
#include "CreateEventDispatcher.generated.h"

// Delegate that can bind to multiple UFUNCTIONs simultaneously
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FMultiDispatcher);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiDispatcher_OneParam, bool, MyBool);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FMultiDispatcher_TwoParams, bool, MyBool, float, MyFloat);
// DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams 
// DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams 
// DECLARE_DYNAMIC_MULTICAST_DELEGATE_FiveParams 
// ...

UCLASS()
class UCreateEventDispatcher : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()


public: // These are the event dispatchers
	UPROPERTY(BlueprintAssignable, Category = "Alex Quevillon|044 - Create Event Dispatcher")
		FMultiDispatcher MultiDispatcher;
	
	UPROPERTY(BlueprintAssignable, Category = "Alex Quevillon|044 - Create Event Dispatcher")
		FMultiDispatcher_OneParam MultiDispatcher_OneParam;
	
	UPROPERTY(BlueprintAssignable, Category = "Alex Quevillon|044 - Create Event Dispatcher")
		FMultiDispatcher_TwoParams MultiDispatcher_TwoParams;

private: // These are the functions that will be attached to the event dispatchers
	UFUNCTION()
		void OnMultiDispatcherCalled();
	UFUNCTION()
		void OnMultiDispatcher_OneParamCalled(bool MyBool);
	UFUNCTION()
		void OnMultiDispatcher_TwoParamsCalled(bool MyBool, float MyFloat);


private:
	// If you want to delegates to be Blueprint Assignable, they cannot be static.
	// This is why we're using a Singleton for our tests today
	static UCreateEventDispatcher* EventDispatcherSingleton;

	// Set Singleton in constructor and destructor
	UCreateEventDispatcher();
	~UCreateEventDispatcher();

public:
	/**
	 * Get the object you can use to bind yourself to the event dispatchers
	 */
	UFUNCTION(BlueprintPure, Category = "Alex Quevillon|044 - Create Event Dispatcher")
		static UCreateEventDispatcher* GetEventDispatcherSingleton();

public:
	/**
	 * Bind all the event dispatchers
	 */
	UFUNCTION(BlueprintCallable, Category = "Alex Quevillon|044 - Create Event Dispatcher")
		static void BindEventDispatchersCpp();

	/**
	 * Unbind all the event dispatchers
	 */
	UFUNCTION(BlueprintCallable, Category = "Alex Quevillon|044 - Create Event Dispatcher")
		static void UnbindEventDispatchersCpp();
	
	/**
	 * Call all the event dispatchers
	 */
	UFUNCTION(BlueprintCallable, Category = "Alex Quevillon|044 - Create Event Dispatcher")
		static void CallEventDispatchers();

};
Vrealmatic consulting

Anything unclear?

Let us know!

Contact Us