I can’t receive OnClicked event from my button that I have created at UMG.
I have created two classes:
- SMyConfirmationDialog : public SCompoundWidget
- UConfirmationDialogWidget : public UUserWidget
I have added my UMG class to slate using following code:
void SMyConfirmationDialog::Construct(const FArguments& InArgs)
{
...
if (!confirmationDialog)
{
UBlueprint* tmpWidget = LoadObjFromPath<UBlueprint>(TEXT("WidgetBlueprint'/Game/UI/Widgets/ConfirmationDialogWidget.ConfirmationDialogWidget'"));
if (tmpWidget)
{
confirmationDialogBPClass = (UClass*)(tmpWidget->GeneratedClass);
}
if (confirmationDialogBPClass)
{
confirmationDialog = CreateWidget<UConfirmationDialogWidget>(mGameInstance.Get(), confirmationDialogBPClass);
if (confirmationDialog)
{
confirmationDialog->Setup(this);
}
}
}
ChildSlot
.HAlign(HAlign_Fill)
.VAlign(VAlign_Fill)
// Populate the widget
// that code call the 'NativeConstruct' function
confirmationDialog->TakeWidget()
];
}
where
//Confirmation dialog widget
UPROPERTY()
TSubclassOf<UConfirmationDialogWidget> confirmationDialogBPClass;
UPROPERTY()
UConfirmationDialogWidget* confirmationDialog = nullptr;
I have created a function that must calling in blueprint when I pressed button on UMG form:
UFUNCTION(BlueprintCallable, Category = "Actions")
void OnOKPressed();
(Of course I have created Bluprint class based on UConfirmationDialogWidget class)
In Bluprint editor I have created OnClicked handler and connected it with OnOKPressed, but with no luck
Also I have tried used the following code, but also with no luck:
void UConfirmationDialogWidget::NativeConstruct()
{
Super::NativeConstruct();
//
UButton* btnWidget;
UWidget* tmpWidget = GetWidgetFromName(TEXT("OkButton")); //"OkButton" - is the correct name, I've checked
if (tmpWidget)
{
btnWidget = Cast<UButton>(tmpWidget);
if (btnWidget)
{
btnWidget->OnClicked.AddDynamic(this, &UConfirmationDialogWidget::OnOKPressed);
}
}
}
What I am doing wrong? Maybe it is a bug?
Please Help me with it