Delegates as Parameter

Sure, here’s some snippets from our project:

Declaring the delegate type:

DECLARE_DYNAMIC_DELEGATE_OneParam(FOnlineUserImageRetrievedDelegate, UTexture2D*, Texture);

Declaring a method that takes the delegate as a parameter:

/* Retrieves the user thumbnail texture*/
UFUNCTION(BlueprintCallable, Category = OnlineUser)
void RetrieveThumbnail(const FOnlineUserImageRetrievedDelegate& Callback);

Declaring a variable to store the delegate:

FOnlineUserImageRetrievedDelegate ImageRetrievedDelegate;

The implementation does something like this:

void UOnlineUser::RetrieveThumbnail(const FOnlineUserImageRetrievedDelegate& Callback)
{
    ImageRetrievedDelegate = Callback;
}

And to call the delegate something like this:

ImageRetrievedDelegate.ExecuteIfBound(ThumbnailTexture);

And it looks like this in the blueprint:

86888-capture.png

9 Likes