Control UI using WASD instead of Arrow Keys?

Hello, I’ve created a UI Menu that can be navigated with a gamepad or the keyboard arrow keys. This was done by setting the game focus to my UI widget.

However, because my game uses WASD to move, I feel like it would be more intuitive and feel more natural if the player could navigate the menu using WASD as well/instead of the arrow keys. Is there a setting, or perhaps method to do this?

1 Like

Hello, pictures and their descriptions show my workaround.

You can do this in C++ by subclassing FNavigationConfig and setting the SlateApplication to use an instance of your class:

(Mile-high view assuming you are familiar with C++ side programming in the engine)

class GAME_API FGameNavigationConfig : public FNavigationConfig
{
public:
	FGameNavigationConfig() {
	KeyEventRules.Reset();
	
	KeyEventRules.Emplace(EKeys::A, EUINavigation::Left);
	KeyEventRules.Emplace(EKeys::D, EUINavigation::Right);
	KeyEventRules.Emplace(EKeys::W, EUINavigation::Up);
	KeyEventRules.Emplace(EKeys::S, EUINavigation::Down);
}
};

Then to set these rules (I did it in my game mode Login function):

FSlateApplication::Get().SetNavigationConfig(gameNavigationConfig);

where in my GameMode definition I have:

TSharedRef<FGameNavigationConfig> gameNavigationConfig;

and my GameMode constructor:

MyGameMode::MyGameMode() : gameNavigationConfig(MakeShared<FGameNavigationConfig>())

Note you might have to add some Modules to the project:

PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore", "InputCore" });

Hope this helps

6 Likes

I call FSlateApplication::Get().SetNavigationConfig(gameNavigationConfig); in BeginPlay, also works! Do you know how to change Confirm key from space bar to Enter? Thanks!