top of page

Custom Checkboxes in Unreal Engine

  • Oliver Stanton
  • Sep 13, 2021
  • 3 min read

Updated: Sep 21, 2021

First attempt:

My first attempt was actually quite successful. Although it was extremely disorganised and very unoptimised. It used two Multigates to switch between the states. Now, a Flip Flop would work fine in most cases, however, when you want to go from A to B when the checkbox thinks you’re on B isn’t possible (from what I’ve found). An example of this is having the A from the Flip Flop go to checking the checkbox, and the B go to unchecking it. When the checkbox is unchecked, this works fine. However when you set the checkbox’s state to checked from an external factor (like BeginPlay or by pressing a button, etc.), then it doesn’t execute the next part of the Flip Flop and instead thinks that it’s still on A, so you need to press it twice to get to B. Or it think it’s on B but hasn’t changed the state itself, so you need it press it twice to get it unchecked. My super complex Multigate solution fixed this, however it was extremely unoptimised and borderline impossible to understand.

The exec pin going into the Branch is from the Tick event:


Second attempt:

My second attempt is blindingly obvious and simple, when I thought of it, it was a true “light bulb moment”. Coming off the Button Clicked event, I had a branch checking if “IsChecked” is True or False. If it’s True, then I set it to false, and vise versa for if it’s False. This would perfect, although one problem I can see arising is not being able to use it on anything other than a one-time event like Clicked, as that will most likely run through the branch on one output and never change to the other output. Another thing that might be a problem is the speed of the Branch node. I’m not certain for sure, but I feel like it takes longer for the Branch to check if something it true compared to the Flip Flop just switching it no matter what. They both faster than my Multigates anyway, so that’s good. There is one more thing that’s wrong with this though. Since the Branch that checks the checked state is in the Clicked event, I still can uncheck it from an external source without first doing something directly to the button to make it update. This is also a combination of the animations being in the Hover and Unhover events, so I need to Unhover the checkbox to play the uncheck animation, which is not ideal. One way you may think to overcome this is to put the Hover and Unhover Blueprints in Custom Events and call those whenever I need (like in the Click event when the “IsChecked” boolean is False). However since the button that is being clicked sometimes is not the checked checkbox (like with tabs, see my other post on that), then Unreal doesn’t know to play that animation, as it’s not the same checkbox you’re clicking. The only mostly working way I’ve found to get this working thus far is to have the unchecked Blueprints in the Tick event, and have the Checked Blueprints in the Clicked event, so then the Clicked event doesn’t need the Branch, and won’t have to worry about unchecking. This means that you can uncheck the checkbox whenever (because it’s in Tick), and clicking on it still makes it check. One problem with this however is that the unchecked animation either doesn’t play, so it snaps from the hover animation straight to not hovering, or it continuously loops the animation, because it’s on Tick. I’ve yet to find a way to make this work properly.

Comments


bottom of page