Hey everyone,
I have a UBoolPropertyRepresentation widget that consists of a property value checkbox and a property name text block.
Below is a code snippet of what I’m doing whenever the checkbox is clicked.
Sometimes it works, sometimes it doesn’t.
if (BoolProperty != nullptr && PropertyValue != nullptr)
{
switch (BoolPropertyValueCheckbox->GetCheckedState())
{
case ECheckBoxState::Checked:
BoolProperty->SetPropertyValue_InContainer(PropertyOwner, false);
break;
case ECheckBoxState::Unchecked:
BoolProperty->SetPropertyValue_InContainer(PropertyOwner, true);
break;
}
}
At first, I thought my SetPropertyValue wasn’t working correctly.
However, I realised that if I run this with the property starting off as true, causing the checkbox to be checked, and I click on the checkbox, the first time that I click the checkbox, the StateUnchecked will run, meaning that Unreal is calling my function after the checkbox state is changed.
For all future clicks on the checkbox, my function seems to be called before the checkbox state is changed.
The only thing I’m doing on my checkboxstatechanged is running the above code.
If I add a Delay before running my code snippet, the ECheckBoxState is only correct if I go into the editor and change it to true.
Then when I click it as true, it says the checkboxstate is false, which makes sense after a 1 second delay.
If I click it as false, it still says the checkboxstate is false.
Very confused!
This seems like it may be a race condition, but it’s hard to know and it seems so unlikely.
EDIT:
Also potentially useful, when instead calling the function with a boolean bIsChecked
instead of the checking the state, everything works, so it doesn’t seem to be the rest of the code.