Check boxes. How to prevent others from checking when one is already checked?

Hi all,

First post here! I´m working on a UMG with 10 checkboxes. Whenever I check one, I want the others not to accept any checking. It sounds easy, and it probably is, but I have done a real mess of nodes and loops to get something semi-working (it kinda works, but it has bugs. It sometimes checks or unchecks the wrong one. It´s a really messy blueprint right now).

Could anybody enlighten me regarding the most usual way to do this? Sounds like something common…

you can add them to an array and before setting them check if any of them are true , But here is the problem with this setup , if player ticks a checkbox and changes his mind and want to tick another he cant do it !

So Add them to an array and before setting any variables , iterate through that array and turn them all false ,Then set the chosen one to true . this way player can choose only 1 and can change his mind after .

Hi. Thanks for the reply. I was already using a similar setup with arrays, but my logic was faulty somewhere. Didn´t find where exactly because today I erased all those nodes, and decided to rethink it from scratch.

Also, because this will be for a mobile game, I don´t want to be able to check another box, until you have unchecked the previous one. That way, if you misclick (mistouch) nothing really happens.
For anyone with the same problem, let me explain what I did because it´s a clean solution and it works very well.

So, I have 9 check boxes, numbered 0-9.
I created TWO variables, which I called “RequestedBox”, and “CheckedBox”. Checked box defaults at 10 (so that by default isn´t any valid number) and RequestedBox defaults at 11 (not important. It just has to be different from the other variable default).
Now, when any of the boxes gets clicked by the user, I store that box value in “RequestedBox”.
If CheckedBox is 10 (everything unchecked), I check the appropiate box (and then I do some other stuff that I need with text inside) and set “CheckedBox” to that number.
If it´s not 10, that means something is already checked, so now I compare if “CheckedBox” and “RequestedBox” are the same number or not.
If they are equal it means the user is clicking on the same box already checked. So I uncheck it, and restore “CheckedBox” to its default value of 10.
If they are NOT equal it means the user clicked some other box different to the checked one, so I uncheck the box the user just clicked (so in effect he´s not doing anything by clicking)

This works wonderfully. Elegant, clear on the BP screen (well…clearer) and simple.
Sometimes coming back with a fresh mind is all you need…

can you make tutorial thank you

Like this perhaps:

If that’s not it, perhaps include some details regarding how it should be working.

This works:

But you can see that you have to add the function to each checkbox event, which is monotonous (however, you can do what Everynone did and bind the events to a single event). Since only one option can selected at a time, consider using a combo box instead, which requires no additional setup.

Here are both in action:

Hey, I’m trying to get over a similar problem and I’m trying to use your method. However when I create the Set Currently Checked Box function there is no parameter on it. I am not quite sure which input parameter to create on the function, I tried a few but none of them were compatible with the Set Is Checked Object parameter. What kind of parameter is on the function? Sorry if this is a very stupid question, I am quite new and still trying to get my head around things.

1 Like

The variable type is “Check Box.” Also, a shortcut for making parameters is to drag a variable onto the function node:
check box

Oh that’s so helpful, thank you!

1 Like

So I created the Set Currently Checked Box function exactly as you show on your original post, and made the links to my checkboxes but it doesn’t work, all of the checkboxes still remain checked when other checkboxes are checked. I have a few more stuff going on in my blueprint - I have expandable areas expanding when the checkboxes are checked, so maybe something is going wrong during that. Any idea what might be stopping it from working?

Well I don’t see anything wrong with what you have. Can I see what you have in your “Set Currently Checked Box” function?

I also added a validated get to my original function, but it’s only necessary if you don’t have one checked from the start:

1 Like

This is it. I will try with the valid get, just in case

1 Like

That looks good. But, I think I just noticed one problem in your other picture. The “On Checked State Changed” event only fires when the user clicks the check box, not when it’s changed through code. So when the other boxes are unchecked through code, the code to close the expandable area won’t fire because the event isn’t being fired. So the expandable areas will stay open.

1 Like

That’s it! I just noticed the checkboxes actually do get unchecked but the expansion areas are the problem. What is the best way to solve this? I thought the checked state is what mattered, didn’t realise actual clicking had an effect…

For the function, you would just add the expandable area as a parameter and enable/disable it in the function the same way the check box is done.

1 Like

This worked like a charm, thank you so so much!

1 Like

Sorry to be a nuisance but I have a submenu of checkboxes in one of the expandable areas connected to the one of the main menu checkboxes. I want these buttons to be clicked and unclicked the same way as the others, but if I connect them to the same Currently Checked Box function, when checked, it will close the expandable area it is in as well. So I created another function for this submenu and did the exact same setup as previously. It doesn’t work. Am I thinking in a wrong way here?

I’m blind :sweat_smile:. All the variables are the same:

1 Like

Gosh I feel stupid now… Thanks for this!

1 Like

Seems like you already got this sorted.

Just wanted to point out that when you have a set of things and you can only select one, that’s a Radio Button.

Not sure if this makes any difference in UMG, since 99% of the time I code my own things to accommodate the slur of missing features anyway.

But if they have a radio button option, it just may automatically manage what’s checked without you having to jump though hoops as you did.