Download

[UMG] RadioButton via Checkboxes

Hello. First of all, I’m kinda new to UE4. Been looking for answer for 2-3 hours and still can’t seem to find it. Thing is, I have group of several checkboxes. Since there is no way that I know of to add radiobuttons in UE4 I’ve decided to try and make logic for checkboxes in blueprint. And so, another obstacle. I can’t seem to alter states of checkboxes, or I just can’t find the function that does so. What would be the best approach for solving this?

You can change their state by calling, SetCheckedState.

We implement radio buttons by binding multiple checkboxes to functions that check if it’s their specific checked state that’s been picked, rather than trying to invalidate all checkboxes that don’t have the correct state.

Lets say we use this for difficulty selection. And user clicks on one of listed difficulties, lets say easy, medium, and hard. User decides easy won’t do it for him and changes to normal. If that is their specific state everything would be okay, but difficulty state should still be unchecked. Shouldn’t we make a pass through all checkboxes and reset them to their default values, unchecked in this case?

No, by setting up the current value of the widget as a binding, the checkbox refers to the function to get its current state. Bindings replace static values with a delegate instead, lets you solve some of these sorts of ‘keeping everybody on the same page’ problems.

Not sure I understand what you mean. So you create a separate callback function for each checkbox which updates the last picked?


UCheckBox* LastPicked;


void CheckBoxOneChanged(bool bIsChecked)
{
if(bIsChecked)
LastPicked = CheckBoxOne;
}

void CheckBoxTwoChanged(bool bIsChecked)
{
if(bIsChecked)
LastPicked = CheckBoxTwo;
}

Then each checkbox has another separate function checking if they are the last picked bound to Checked State in the UMG editor?


ECheckBoxState CheckedBoxOneState()
{
  if(LastPicked == CheckBoxOne)
    return Checked;

  else
    return Unchecked;
}

ECheckBoxState CheckedBoxTwoState()
{
  if(LastPicked == CheckBoxTwo)
    return Checked;

  else
    return Unchecked;
}