In this blog post, we’ll go over the basics of keyboard events in Unreal Engine and how they can be used in Blueprints.
How to use Keyboard Events in Unreal Engine?
Using keyboard events in Unreal Engine Blueprints is a simple process. Here are the steps to follow:
- Right click in the Blueprint Event Graph
- Search for “Keyboard“, or look for “Input → “Keyboard Events”
- Finally, choose the key you want to use to start an event.
- Another option is to search directly for the key you want, like “F keyboard,” instead of scrolling through the entire list.
- All of the keys on the keyboard are listed in the dropdown list.
Input Key: Pressed vs Released
When a key is “Pressed,” it means the user has physically pushed it down but it has not yet been released. Unreal Engine detects this action and activates the appropriate keyboard output.
When a key is “Released,” it means that the user has let go of the key and it returns to its original position. This will activate the keyboard Released output.
Keyboard events for both “pressed” and “released” states can be captured separately in Unreal Engine. This enables game developers to create more complex gameplay mechanics that respond differently to specific keyboard inputs. A game, for example, could use a “pressed” event to cause a character to jump and a “released” event to cause the character to perform a special move in mid-air.
Understanding the difference between “pressed” and “released” events is critical for developing responsive and engaging gameplay mechanics that are intuitive to the player.
To test the difference inside the engine, try connecting a Print String node to the pressed and release inputs.
Why is the Key Event Not Working?
If you try to use a Keyboard Event in a Blueprint actor other than your character or pawn, you may run into problems.
It is possible that the Key Event won’t execute. But why is that?
In general, I wouldn’t recommend enabling input on an actor that you don’t possess because there is usually a better solution that doesn’t cause problems with multiple actors.
But here are three potential solutions to this problem that you can try:
- Connect the Event BeginPlay to an Enable Input node. This will enable input on the blueprint.
- Remember to connect the ‘Get Player Controller‘ node as well.
- Change “Auto Receive Input” from “Disabled” to “Player 0” inside the Blueprint’s details panel.
- Just check that the Blueprint is active on the level and that appears in the Outliner. This may appear overly simple, but it is a common error.
More keys using the same input?
Click in the Keyboard Event Node and look at the details panel, you’ll see the “Consume Input” option.
If checked, it stops the actor with the lowest priority from handling this input.
In case you have input conflicts due to numerous inputs utilizing the same key, be sure to check or uncheck this option based on your needs.