Download

How to add C++ method to add event in blueprint?

Hello all!

I recently found this page which I’d like to do. I think the code can do what I want (I simply want to detect Escape key and Tab key when text box has keyboard focus).

I have some experience with blueprint and widget blueprint, but none in C++ coding. I have no idea what I’m looking at or what to do with his code. Can someone link me a guide or explain below how I can implement his code so I can use it in my widget blueprint?

Thank you!

Detailed guide: https://wiki.unrealengine.com/UMG,_H…MG_in_C%2B%2B.

Quick guide:

Add this to your widgets header:
.H
UPROPERTY(meta = (BindWidget)) UButton* StartMissionButton;

UFUNCTION() void OnMissionStartClick();

In the editor your button control’s name will be StartMissionButton and you should check the Is Variable checkbox
The “meta = (BindWidget)” lets Unreal dynamically bind the control.

.CPP

void UYourWidgetClass::NativeConstruct() {
Super::NativeConstruct();

if (!StartMissionButton->OnClicked.IsBound()) StartMissionButton->OnClicked.AddDynamic(this, &UYourWidgetClass::OnMissionStartClick);

}

void UYourWidgetClass::OnMissionStartClick() {

}