I cannot bind a boolean in my BP widget.
.h
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool MyBool;
When I bind to this variable in the BP Editor, I cannot change its value. It’s always set to true. What am I doing wrong?
I remember seeing someone else posting and answering this same question but I can’t find it.
Thank you for the help.
I ended up binding to an ECheckBoxState variable and calling a function in my class when the UI value changed:
.h
UPROPERTY(EditAnywhere, BlueprintReadWrite)
ECheckBoxState MyCheckboxState;
bool MyBoolVar;
UFUNCTION(BlueprintCallable)
virtual void CheckBoxChanged(bool isChecked);
.cpp
void UMyWidget::CheckBoxChanged(bool isChecked)
{
MyBoolVar = isChecked;
if (MyBoolVar)
MyCheckboxState = ECheckBoxState::Checked;
else
MyCheckboxState = ECheckBoxState::Unchecked;
}
-
I wouldn’t expect to have to do this in order to bind variables. I should be able to bind to a boolean, float, enum, FText, FString, int32, uint32 and documentation should clearly state how to do it.
-
I shouldn’t have to set the checkbox state in the above code but do so just to make sure that the UI and I are on the same page. If my variable is TRUE, I’m making sure that the checkbox state is also TRUE, meaning CHECKED (or as the case may be).
I could rewrite the function to a single line:
void UMyWidget::CheckBoxChanged(bool isChecked)
{
MyBoolVar = isChecked;
}
Which is kind of silly. Why don’t I just bind to it in the first place?
I suspect that I’m doing something wrong.