Making changes to games is a guarantee when it comes to production. Because of this you want to make it easy as possible to make changes to your game mechanic. Input actions are one way to do this. They mean that you can make a single change, and any blueprint that uses that input action will get updated. As you can imagine this can be a life saver, and something you will look at setting up here.
- [Teacher] Game inputs give us the ability to predefine an in-game action, as well as to specify a number of keys or controls that can then be linked to that action. This means that we can then reference inputs from inside our blueprints and not have to worry about telling the game which specific keys are supposed to be used each and every time we want to execute that particular action. As we will be referring to this input later on in our blueprint code, we're going to want to give it an easy-to-understand and descriptive name.
Now, we could've caused bind keys manually inside the blueprint, something that I would do if I were tying this mechanic into a system that allowed the player to change or remap the keys being used in the game, but simply pre-assigning the keys here will make things a little bit easier and save us time when it comes to working in our blueprints later on. To add an input action to our game, we need to come up to our menu headers, and after clicking on the edit menu fly-out, select project settings from the list.
We can then maximize the project settings window to make it easier to see, and click to enter the inputs action. After expanding the action mappings list, via the tool down arrow, let's click the plus icon to add a new action, calling the action Sprint, for obvious reasons. Then, from the drop down that is available, let's choose the left-shift key as the action input. Then, we can speed up the selection process here by typing shift into the search field if we would like.
Now, for the purpose of this tutorial, I'm going to be using the tried and tested left shift key control, which, for sprint actions, should be familiar to most PC gamers out there. Do keep in your mind, though, that this action can be mapped to a number of different inputs at the same time if we like, including those found on a controller. Do feel free then, to add something like a left thumbstick click, or even the A button, if you're wanting to create the sprint mechanic for a console game.
As you can imagine, setting up game inputs in this way can make life a lot easier down the line should we decide that we would prefer to to use a different set of input controls for an action. Rather than potentially having to change lots and lots of shift key nodes, in the blueprint now, all we need to do is come back to our inputs menu, change the key assignment here, and then all of our blueprint work will update accordingly. Nice, quick, and easy.
- Creating the project
- Making the input action
- Building the sprint blueprint
- Timelines and input control
- Variables and lerps
- Adding the walk and run variables