Help with Context Sensitive Key bindings

Hey all,

So I’m having a problem setting up the control scheme for my game. I want the controls to be fairly simple with only two buttons for the gameplay. As such, I was hoping to set up a modifier key that you can hold down to get extra use out of the two main buttons. I’ve looked into setting up multiple key presses and most people say to use booleans but I don’t think this will work in my case.

For my game the character is swimming. When you press the Left mouse Button it works their Left Arm moving them right, the Right Mouse works the Right arm moving you left, and pressing both at the same time will make both arms go moving you forward. The Modifier key is Reverse which makes you swim backward if you’re holding it and both mouse buttons at the same time.

Here’s my setup:

So the problem as you can see, is that by using Booleans, it’s registering as true for MULTIPLE events when I hold down Left Mouse, Right Mouse and the “Reverse or Modifier” key.

Also the issue with booleans is that if I’m holding Left and Right mouse to swim forward and then I just press the Reverse key too, it ignores the reverse command and I keep moving forward.

There has to be a better way to handle something like this but I’m not sure what it is.

No one has any advice on how to do something like this?


The big problem here is, all four Branches+Sequence are operating like four logical OR’s!
Each Branch ‘FALSE’ Pin should actually connect to the next Branch Exec-Pin-In, below it…
So don’t use a Sequence node here at all…Connect each Branch False to the next Branch.
Infinite ways to do this, but for now rewire everything to read as follows without a Sequence:

Swim-Right-Pressed AND NOT Swim-Left-Pressed AND NOT Reverse-Pressed -> True -> Swim-Right
Swim-Left-Pressed AND NOT Swim-Right-Pressed AND NOT Reverse-Pressed -> True -> Swim-Left
Swim-Right-Pressed AND Swim-Left-Pressed AND NOT Reverse-Pressed -> True -> Swim-Forward
Swim-Right-Pressed AND Swim-Left-Pressed AND Reverse-Pressed -> True -> Swim-Backward

Overall, take a look at some kind of Finite-State-Table solution if you’re going to be doing lots of this.
Also, there’s a built-in BP node already that uses a Player-Controller ref, to help simplify all this code:


Ok yeah, I thought that maybe there was a better option to using branches and bools all together because if you have to run everything on the false of the last node then it’s a really long check every time and I figured it wouldn’t be very optimized.

Thanks for the breakdown though.


Instead of Branches / Bools, you can also use Gates triggered by Input Pressed / Released events. Along with Is-Input-Key-Down, you can get a lot done in less steps. But again using FSM (Bruno Xavier’s plugin etc) may help if things get complicated quickly. Also, the downside of the code above, is that all the ANDS get evaluated. Have a read here if you haven’t seen this thread before. In short, using too many Pure nodes like AND / SELECT can be a real liability.

So one other work around to help simplify things, is place logical clauses that are more likely to fail first or earlier-on in your logic branches. In the example above, have REVERSE-PRESSED as the first branch as there’s no advantage to evaluating Left / Right first etc. But overall with BP nativization, don’t sweat the little things. Its not like you have 100’s / 1000’s of these in Tick, whereas other things like Draw-Calls etc, will probably hit you every time versus this…

Thanks so much for the reply Franktech. That was exactly what I was looking for.