Prompted by a marketplace question I decided to try combining thumbstick and mouse control for cursor UI in a project. This quick blueprint approach shows one way to do it:
Under the Edit drop-down menu, I went to Project Settings > Engine > Input > Bindings > Axis Mappings and added an Axis Mapping for a controller left thumbstick Y-axis (I named it ThumbstickY) and likewise I added an X mapping and named it ThumbstickX.
(If anyone is not familiar, ACTION mappings are bindings for on/off inputs like button presses, mouse-clicks, etc, while AXIS mappings are bindings for analog/variable inputs like mouse movement, joysticks, steering wheels, etc.)
With those two mappings I added this script to a blueprint:
Whenever input from the thumbstick is enabled, its input will be added to the mouse position. This means the cursor can be operated by either mouse or thumbstick (or both).
This can be improved on, and I think some mouse nodes are different in UE4, but hopefully it’s a helpful example.
(The event and get nodes that have ThumbstickX or Y in the name are calling the name of my axis mappings. If you used a different names then search for nodes of those names)
As you can see, it just handles cursor movement. For mouse clicking, you would create an Action-mapping and eg if using a Widget Interaction Component you would connect the Action-mapping to the Press Pointer Key node when pressed and Release Pointer Key node when released.
Worked great! Also to test, I had add to disable movement in the demo because I kept moving out of the trigger box, and with the right thumbstick, you look all over as the mouse moves. But will be great in gameplay, because it won’t be trigger boxes opening it. Thanks!
Picked up the Top Down Shooter asset that was on sale on the Marketplace and can confirm that it works with it and on UE v4.27 as well. I just added the Axis Mappings and put the code into the character BP. Thanks RHA.
Hey, Just Ttried this and everything works great except my mouseY axis is flipped, any suggestions? NVM I JUST HAD TO SET THE MULTIPLY VALUE TO NEGATIVE FOR THE Y EVERYTHING WORKS NOW THANKS!
Any chance we could get a blueprint visual of that mouse click explainer you included in the last graf? Would love to visually see how that’s set up for a complete “Xbox controller=mouse” menu solution.
Also–I followed the thumbstick-to-cursor steps and now my cursor drags itself down to the bottom right corner of the screen automatically–why is that?
That drag is probably the deadzone that is slightly off.
In the input action, you can either add a parameter for deadzone OR in the input axis, make both X and Y abs, add them together and if below a threshold, ignore it. I found mine to be 0.15 .
My issue with this is that I get inconsistent results.
If I start the game, the first movement I make, will move the cursor and then stop BUT there is now an invisible cursor moving around.
I have to continuously move the cursor and the gamepad to get a consistent cursor following.
The Mouse click is unfortunately broken up until 5.2 apparently. But I think it looks like this:
It didn’t work for me and I’m in 5.1 but I cannot take the risk to go to 5.2 currently.
The workaround for the clicks is to have all your buttons set focus when hovered over and then the focus portion of the UI will take care of the input. Which is dumb…