I’m trying to use UMG for my game menus but my game is suposed to be used with gamepad and I don’t know how to bind the keyboard/Gamepad buttons to move along the menus.
In the 4.6 release it is suposed that we can do it:
UI: GAME CONTROLLER SUPPORT
You can now navigate between UI elements using a joystick!
By default you can use the arrow keys, directional pad or left joystick to navigate. You can still use Tab or Shift+Tab as well. This works with both Slate and Unreal Motion Graphics.
We’ve unified the concept of “Keyboard Focus” and “Controller Focus” into “User Focus”. Changing user focus will affect all controllers and keyboards for that user.
Am I missing something?
Can someone make a little tutorial on how to achieve this?
I’ve tried to search documentation about this but i didn’t find anything useful for me.
I too am interested in this information. For now I handle all the states manually, and when a controller/keyboard direction is hit the player controller fires an event on the widget that will check which option you currently have selected, and which one should be selected next. It’s not ideal for sure. Then I have to handle the hover/pressed states of the button manually.
The closest I’ve been able to get this is by putting a bunch of buttons into a vertical container and then when you click anywhere inside the container you can then cycle through the buttons on your controller. It’s a bit impractical but it’s the closest I’ve got to get it working. I’m also interested in working out how to get it working without having to do clicks.
I also am trying this, I think its not really implemented properly yet so far,
What I do is in c++ grab the widget I want TakeWidget() and then use SlateOperations.SetUserFocus() to set the focus to that widget, this lets me use my gamepad, although I have no idea how to change the visuals of that dashed edge you get.
My guess is we have to either learn Slate or wait for better support for UWidgets
I ended up doing it all manually in c++. I keep a navigation ring of button pointers and manually set the ‘hover’ state of all my buttons (at the slate level) depending on the gamepad input events.
It works perfectly with gamepad and mouse/keyboard, but of course it would be awesome if the built-in navigation system actually worked!
Hi Cgrebeld, so did you bind some function to “W”(some key) with function and in the function you invoke like “OnClicked” event of UMG Widget’s button? How would I get pointer to a button of the UMG widget in code?
@CodeSpartan
Not working for me, I have placed my buttons in ‘Horizontal Grid’ and have added different images for Normal, Hovered and Clicked state under Style section. Even unchecked ‘Is Focusable’ under interaction section.
Further I tried checking ‘Has Keyboard Focus’ which always returns ‘False’. I am not able to have keyboard focused on the button, any assistance please.
I’ve just tried my sample project with an Xbox controller - you can both navigate and press buttons. You can download it from the link above and check for yourself.
To remove the dotted line you can create a class derived from “UGameViewportClient”, then you put that class in your DefaultEngine.ini, below [/Script/Engine.Engine] you must add this line “GameViewportClientClassName=/Script/YourGame.YourGameViewportClient”.
In that class you must overwrite the function