Tower Defense Starter Kit: How to assign Hotkeys to Global Abilities

The Tower Defense Starter Kit comes equipped with a host of Global Abilities that can be activated by the player during gameplay. As of the v2.27 edition, the toolkit contains the following abilities: Airstrike, Tower Guardians, Proximity Mine, and Regen Field.

By default, using these abilities require first selecting the required ability through the Global Ability buttons displayed on the bottom left corner of the screen and then activating the selected ability by targeting an appropriate location on the map. This tutorial aims to provide you with the steps required to implement hotkey support for quickly selecting the global abilities.

1. First open up the Widget_GlobalAbilityButton blueprint and add the following nodes:

This event will help us directly control the ability button selection states without requiring the player to click on the button.

2. Now head over to the Widget_GlobalAbilities blueprint and add the following function to it:


This blueprint essentially acts as a container for displaying all the global abilities in the player's arsenal during gameplay. And the new function we're adding here will lets us access the ability buttons using indices associated with our ability hotkeys.

3. Now that we've covered the changes to the UI part of the workflow, we'll need to add the logic to call these UI changes. So copy the event shown below into the BP_PlayerController blueprint.


4. Before finally adding the input controls, we'll first add input mappings for our ability hotkeys through the Input section under Project Settings.


5. And now for the final step, just add the input events for these hotkeys in the BP_PlayerPawn blueprint and have them call the event we added in player controller. Also make sure to start the indices for your abilities from 0 instead of 1 since we're essentially using it to access an array of widgets.


Alright, that's all there is to it. Now you should be able to select global abilities in your game directly through your assigned hotkeys. Pressing the same hotkey again should also stop the ability targeting process since we're using already existing code to handle that. So there is no need to write any additional code for that. And if you have any doubts regarding the workflow, feel free to reach out through the comments section.

Comments