How do you setup multiple input actions on the same button?

I’m attempting to setup multiple input actions on the same button press.

Example 1 Weapon Switching:
Pressing a button once equips the primary weapon.
Pressing again cycles threw to the secondary weapon.
A double tap of the button equips the alt weapon like a pistol or heavy weapon.

Example 2 Multiple interactions on the same button press:
Press a button to reload.
Press this same button to open doors.
Press this same button to pickup objects and powerups.

Example 3 Crouch and Evade:
Press a button to evade.
Hold in this button to put the player into crouch.

Can anyone lead me to either an example in one of the example unreal maps, or some documentation, or a youtube vid showing an example setup. Even just posting an example BP of how you solved this problem would be helpful. I have a pretty good grasp of setting up my inputs in the action mappings and calling the nodes in Blueprint. I’m just not seeing the logic for things like detecting if a button is held down or pressed fast in succession. If I had some logic that worked for these things I could branch off into the bp I have for reload, crouch, dash, etc. Any ideas? I Def would like to learn best practice for a setup like this.

@xpgained Example1: Unless you’re thinking of the mouse, I’d try another way ( double click is readable ). For keystroke events, I’d just stick with ‘has it been pressed?’

Example2: Much easier. If each interactable object ( ie BP ) implements an ‘interface’ then one button can mean any of these things. Because using interfaces you can just send the message to the object ‘you have been clicked’, and it’s up to the object what to do next ( search ue4 blueprint interfaces ).

Example3: Again not so easy. You can have one button, but it would have to figure out danger was approaching to evade rather than crouching. So here, one for crouch, one for evade.

My advice is check out BP interfaces, you tube is littered with tuuts on that, and it will get you 95% of the way :slight_smile:

It’s all in how you handle it. Logically, what does “holding a button” or “double tapping” mean? It’s all pretty straightforward when you logically step through it in your head.

For checking if a player is holding a button, you could set a function timer on key press, and clear said function timer on release. If it hasn’t been released, it’ll execute the logic inside the function.

For double tapping, set a float (LastPress in this example) to the current time, every time you hit the key. Before setting said float, check it to see if CurrentTime - LastPress <= 200 to 300 milliseconds (tweak to your liking). If so, they’ve double tapped, execute the double tap logic.

For using the same key to interact/reload, it’s just more logic to step through conceptually. If you’re already detecting that an interactable object is within range (example, showing something on the screen to indicate to the user that they can open/use it), you’re 95% of the way there. Set some variables like, “ShouldInteract” = true, “InteractWith” = <the object>, etc. Just check for those variables when the key is pressed. Default to attempting a reload if there’s nothing set to interact with.

With all of this logic existing for one key, you have to account for more scenarios, though. Example, I’m about to die and frantically hitting R to reload. Should that door open up which has a flood of enemies behind it? Probably not. User Experience is key here and you’ll have to playtest it yourself a ton to make sure you’re not doing something which will frustrate your players. Another example is crouching and evading in one key. You’ll likely need the evade logic to run on key release, instead of on key press. Then, make sure it only evades if they didn’t crouch. Final example, double tapping. What happens on the first tap? Do you just wait to see if they tap again, or do you execute single tap logic so the game feels more snappy? It could appear janky if it cycles and then goes to the alternate weapon.

My own take on it is to run the logic as quickly as possible so people don’t feel like they have a delay to account for. For a dodge system it’s a lot easier since tapping right will move right, and double tapping will slightly move then dodge. It just feels snappy and responsive. This is a great example of synergy, however. As a player, I don’t mind if I step to the right just a bit before I dodge, and I appreciate that the movement controls don’t “wait” to see if I’m attempting a dodge or just strafing.

In your case, someone could have accidentally pressed the button to cycle, and could be quick enough to tap it again (hoping to get back to their primary weapon) and go to the alternate on accident. Be very careful with how you handle the logic, and remember that being agile is failing often. If the double tap just doesn’t work (or, rather, works but leads to some frustrating edge cases), try something else until you find the right solution. At the end of the day, you don’t want a player to expect one thing, and get a totally different outcome because you’re trying to be clever with keys. Your average gamer would rather have more keybindings than accidentally do something that’ll lead to an extremely frustrating death, for example.

Thanks for the info. I think I need to look into function timers. When you say function timers you are not talking about timelines correct. Function timers are something different?