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…
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.
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.
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?
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.
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…
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?