Hi, I’m using the OnClick event that runs when I click my buttons. I am creating 3 bottones from my Blueprint Widget and I call them from my c ++ code with the UPROPERTY method (meta = (BindWidget)). Now what I want to achieve is to call each button from the same method to avoid creating each call event for each button. that is, dynamically. I already know that from my event I would have to use an “if” but I do not know how to get the button that is being called. Here is my code:
.h:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "MyUserWidget.generated.h"
/**
*
*/
UCLASS()
class GAMEPARTY_API UMyUserWidget : public UUserWidget
{
GENERATED_BODY()
public:
virtual void NativeConstruct() override;
UPROPERTY(meta = (BindWidget))
class UButton* NewGame;
UPROPERTY(meta = (BindWidget))
class UButton* Options;
UPROPERTY(meta = (BindWidget))
class UButton* Exit;
UFUNCTION()
void OnMenuClick();
};
.cpp:
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyUserWidget.h"
#include "UMG/Public/Components/Button.h"
#include "UMG/Public/Components/TextBlock.h"
#include "Engine.h"
#include "MyGameUserSettings.h"
void UMyUserWidget::NativeConstruct()
{
Super::NativeConstruct();
NewGame->OnClicked.AddDynamic(this, &UMyUserWidget::OnMenuClick);
Options->OnClicked.AddDynamic(this, &UMyUserWidget::OnMenuClick);
Exit->OnClicked.AddDynamic(this, &UMyUserWidget::OnMenuClick);
}
void UMyUserWidget::OnMenuClick()
{
}