// Step 1: Include necessary headers
#include "YourClass.h"
#include "YourDelegateClass.h"
// Step 2: Declare the delegate signature in YourDelegateClass.h
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FYourDelegate);
// Step 3: Declare the delegate instance in YourClass.h
UPROPERTY(BlueprintAssignable, Category = "YourCategory")
FYourDelegate OnYourDelegate;
// Step 4: Implement a function to be called when the delegate is executed in YourClass.cpp
void UYourClass::YourDelegateFunction()
{
// Your implementation here
}
// Step 5: Bind the function to the delegate in YourClass.cpp (e.g., in BeginPlay or constructor)
void UYourClass::BeginPlay()
{
Super::BeginPlay();
OnYourDelegate.AddDynamic(this, &UYourClass::YourDelegateFunction);
}
// Step 6: Call the delegate from a Blueprint (e.g., in a custom event)
// YourBlueprintFunction in YourClass blueprint graph
UFUNCTION(BlueprintCallable, Category = "YourCategory")
void UYourClass::YourBlueprintFunction()
{
// Call the delegate
OnYourDelegate.Broadcast();
}