Hi all,
I am currrently working on a project and I learned how to call events for UMG Button Widget in C++ by using
the AddDynamic macro.
The problem I have is that the AddDynamic macro only works for calling events (such as OnClick) on Button Widgets only.
I am not sure how to call the events for Slider, CheckBox and ComboBox string Widgets.
Below is my code:
Header file: MainMenuVer2.h
UPROPERTY(meta = (BindWidget))
class UButton* Play;
UPROPERTY(meta = (BindWidget))
class UButton* Settings;
UPROPERTY(meta = (BindWidget))
class UButton* Quit;
UPROPERTY(meta = (BindWidget))
class UButton* Return;
UPROPERTY(meta = (BindWidget))
class USlider* sliderVolume;
UPROPERTY(meta = (BindWidget))
class UComboBoxString* resBox;
UPROPERTY(meta = (BindWidget))
class UCheckBox* fullScreenCheckBox;
As you can see in my header file, I already referenced all the UMG widgets created in my Widget BP.
I also already reparented this C++ class to my widget BP. See image below:
Source file: MainMenuVer2.cpp
//The following 4 lines for button widgets can call their event function when using AddDynamic
Play->OnClicked.AddDynamic(this, &UMainMenuVer2::playGame);
Settings->OnClicked.AddDynamic(this, &UMainMenuVer2::enterSettings);
Quit->OnClicked.AddDynamic(this, &UMainMenuVer2::quitGame);
Return->OnClicked.AddDynamic(this, &UMainMenuVer2::exitSettings);
//The following 3 lines event function can't be called using AddDynamic
sliderVolume->OnValueChanged.AddDynamic(this, &UMainMenuVer2::changeVolume);//Slider Widget
fullScreenCheckBox->OnCheckStateChanged.AddDynamic(this, &UMainMenuVer2::changeFullScreen); //Check Box Widget
resBox->OnSelectionChanged.AddDynamic(this, &UMainMenuVer2::changeResolution);// Combo Box String Widget
I can call the onClick event for the Buttons using AddDynamic, but it doesn’t work the same way for the slider, checkbox and comboBox string.
These are the error messages that I got:
Severity Code Description Project File Line Suppression State
Error (active) E0304 no instance of function template “FOnCheckBoxComponentStateChanged::__Internal_AddDynamic” matches the argument list PatrolDemo
Error (active) E0304 no instance of function template “UComboBoxString::FOnSelectionChangedEvent::__Internal_AddDynamic” matches the argument list PatrolDemo
Error (active) E0304 no instance of function template “FOnFloatValueChangedEvent::__Internal_AddDynamic” matches the argument list PatrolDemo
So how do I call the event for slider, CheckBox and ComboBox string?
Any help is appreciated.