I’ve tried to create a custom OnClicked delegate for custom Button (inherited from UButton), that passes self-reference, but it is not exectued when I click a button.
Header:
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnButtonClickedRefDelegate, UExtendedButton*, ButtonRef);
UCLASS()
class DQS_API UExtendedButton : public UButton
{
GENERATED_UCLASS_BODY()
public:
UExtendedButton();
/** Should be called when the button is clicked, also gives the reference to this... */
UPROPERTY(BlueprintAssignable, Category = "Button|Event")
FOnButtonClickedRefDelegate OnClickedReferenced;
UFUNCTION()
void OnSelfClicked();
UFUNCTION()
void DoSomething(UExtendedButton* ButtonRef);
protected:
/** Handle the actual click event from slate and forward it on */
FReply SlateHandleClicked();
};
Source:
UExtendedButton::UExtendedButton(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
OnClickedReferenced.AddDynamic(this, &UExtendedButton::DoSomething);
OnClicked.AddDynamic(this, &UExtendedButton::OnSelfClicked);
}
void UExtendedButton::OnSelfClicked()
{
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red,
FString("Hello :: ").Append(this->ButtonText->GetText().ToString())
);
OnClickedReferenced.Broadcast(this);
}
void UExtendedButton::DoSomething(UExtendedButton* ButtonRef)
{
OnClickedReferenced.Broadcast(ButtonRef);
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red,
FString("Do :: ").Append(ButtonRef->ButtonText->GetText().ToString())
);
}
/* Cannot be overwritten since the original one isn't virtual... */
FReply UExtendedButton::SlateHandleClicked()
{
OnClickedReferenced.Broadcast(this);
return FReply::Handled();
}
I couldn’t set things right as in [here][1], since I didn’t expect to touch Slate at all, only UMG.
What I want to achieve is this BP working: