Hi! I’m new to unreal and blueprinting but I’ve been learning a ton on this forum/youtube. I’m trying to make a prototype for an action-comedy/horror game.
I want to be able to input two buttons at once for an action(in this case, both shoulder buttons on the gamepad).
I figured out how get that to work, but I find it a little tough to nail it each time, so I’m wondering what a good method would be to make it a little more forgiving (so if you dont press the shoulders at exactly the same time, it’ll still work).
I’m not sure what to even search for, so any help(even just words I can use for my google searches) would be super helpful. Thanks so much for any time you can spare!
Feel free to share what you have so far.
One way you could implement this is to keep track of which button is pressed/held in your PlayerController/Pawn class (whichever you’re using for handling input). To start with, set a boolean value to true for each button you want to be pressed for the action. In this example, I’m checking if the left shoulder button and the bottom face button (A on Xbox) are pressed:
Then using your Tick event, you can track the pressed state and time an input has been waited for and activate what you want the input to do or reset the timer and input status as necessary. First, you’ll want to check if both are already pressed, in which case you can just go ahead and activate your special event:
For the “Do the Thing” node, you can use a custom event or a function, or even put your logic directly into the Tick event. I just set up this custom event for this example:
For the False branch of that check, you can do another check to see if one button is down, and if so, update the timer for waiting on the second input:
Since there’s nothing to do if neither button is pressed, the False output on the XOR can be left empty. Then check if the Current Wait Time has exceeded the amount of time you’re willing to wait for an input, and if so, reset the timer and input states:
The other input on the above image is the output from the “Do the Thing” event in the second image since you should reset the timer and input state after a successful activation as well. Here’s the full Tick setup to make sure you get all the connections right:
The last thing you should need to do is set the Wait For Input Time variable to how many seconds you want to buffer the input by. For example, if you set it to 1.5, you’ll have 1.5 seconds from the first button press to hit the second one for the check to succeed.
I didnt see this previous post!!! This is amazing, I will try it! Thank you!
worked perfectly, thanks again!
You’re welcome!
This can be done without the need of tick event… in case you are interested.
Yes of course, I’d love to learn how to do it!
I would suggest making a custom even that uses/checks the 2 variable.
Then you can simply set it as the end bit of each input.
Whenever one is pressed, the event is firing and checking the variables before going futher into the execution.
maybe you can also drop the event.
Afterall, the event call can be cumbersome, and there’s really no need for it other than to avoid using 2 branches…
Each input will simply branch and check for the other boolean before being linked into the same code when that other boolean is true.
Note that neither of these solution is really ideal when dealing with input.
The proper way to handle things would be the implementation of an input buffer, and adding or replacing events on a stack.
This is actually almost a necessity if you then have to deal with network replication…