Race Condition in UMG Checkboxes?

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.

Why you making all this synchronization code and not just bind the varable to the checkbox? You know how Slate operates right?

Good point! I’m not actually using Slate. I’m instancing a UUserWidgets from a TSubclassOf<UUserWidget> so that an artist can edit a widget using UMG and then I can generate the widget across all menus. There’s a widget for Bools, Ints, Floats, and Strings. It’s probably not the best way to do things!

Definitely brings up the point that maybe this is expected behaviour. I expected the checkbox state to be the “requested” state, but returning the actual state maybe makes sense. I’m going to go ahead and close this since it doesn’t really seem to actually be a bug at all.