Creating Custom Event Delegates!

Hey a quik example of this:


// Header File over the class.
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSomethingHappendSignature, bool, bWasItTrueOrFalse);

Note that you devide the data type (bool) and the param name with a “,”.
Now add it as a new member to your class.


public:

	UPROPERTY(VisibleAnywhere, BlueprintAssignable, Category = "Your Delegate")
		FSomethingHappendSignature OnSomethingHappen;

When the thing you want to Broadcast happens you do the following.


OnSomethingHappen.Broadcast(bWasTrue);

To Bind to this event in a difrent class you can do the following to bind the event to a function in a other class.


// In your source file in a second class.
PtrToClassWithDelegate->OnSomethingHappen.AddDynamic(this, &ASecondClassName::FunctionToCallWhenOnSOmethingHappenFires);

Also note that the function you bind to needs to have the same parameters as the delegate, in this case one bool value.
And as long as the delegate is BlueprintAssignable, you can get it in Blueprints as well.
Don`t forget to check your pointers ;).

Hope this helps.

2 Likes