NEED HELP: Single Player Controller with Input Contexts

TL;DR - I want to add keyboard/gamepad input for selecting items in Main Menu. You press button, you select next/previous menu item/option: Play, Load Game, etc.

I just don’t know what I’m asking for anymore.
I’m trying to make Player Controller, handling Title/Main Menu, Gameplay and Pause Menu.

At first I was thinking about making separate Player Controller classes.
One for Main Menu (CndController_Title) second for Gameplay/Pause Menu (CndController_Player).

I only keep finding the basic tutorials with Hover and Press, that don’t cover any of this.

Already made Input assets for Menu. I just don’t know how make them work inside my Main Menu widget.

I think the best way, based on the engine design, is to use a Player Controller for the Menus (instead of handling input in the Menu’s tick, for example).

Then, maybe the best approach is creating a Game Mode and Player Controller specific for the Menus. You may find some menus/UI that can share the same Game Mode/Player Controller.

Okay, but how is that supposed to be helpful?

Hello @GraczCourier ,
You could use CommonUI, since it allows your UI to work properly with keyboard, mouse, gamepad, or touch without having to write different logic for each one.

Also, if you want to have specific buttons for each function, you can try using InputActions and InputMappings.

Here’s a simple example of how to use CommonUI, along with some documentation and a link to the learning page, where you can find many examples of how to use it in different situations that might help

Documentation

Learning Site

Example:

First, enable the CommonUI plugin.
Go to Edit - Plugins- Common UI and enable it, then restart the editor.

Next, in Project Settings, look for Game Viewport Client Class and set it to CommonGameViewportClient, you’ll need to restart the editor again after that.

Create a new Blueprint using CommonActivatableWidget , this will be your main widget.

Then, wherever you want the widget to open (in this example, when pressing the 3 key or the Start button on the controller), create the following setup.

In your widget Blueprint, override the function Get Desired Focus Target so that it returns the first button you want to focus on when the menu opens.
This ensures that the focus starts there when using a controller or keyboard.

When closing the widget, you can use something like this.

With this setup, your UI should be fully controllable with a gamepad or keyboard.

I’m also leaving you the documentation about Input Actions and Input Mapping Contexts, which might be useful.

Hope it helps!

1 Like