How to handle mouse and touch input simultaneously?

Godot Version

4.4.1

Question

Hey, I’m trying to make my game accessible on as many platforms and input methods as possible. This means handling both mouse and touch (and KB and controller ontop of that).

The setting “Emulate Mouse from Touch” doesn’t work for me, because I have an action already bound to LMB and every time I touch the screen, it immidiately sends a left click, which makes my game unplayable, so I disabled it.

I’m using GodotTouchInputManager or “GDTIM” (GitHub - Federico-Ciuffardi/GodotTouchInputManager: Asset that improves touch input support (includes new gestures) in the Godot game engine. It also translates mouse input to touch input.) to handle touch gestures, and it’s been great, if a little hack-y at times, due to the fact you can’t just bind them in the input map like you can mouse, kb and controller (or can you? - if that’s possible, please let me know!)

However, UI is where I hit a road block. Without the “emulate mouse from touch” option, buttons just don’t respond to taps. GDTIM acknowledges this and recommends I disable the button’s mouse filter, so it doesn’t consume the input, but if I do that, the buttons stop reacting to my mouse either! Is there an elegant solution that can make my taps on buttons work?

And by elegant I don’t mean checking coordinates to see if a tap originated from within a button’s boundaries, and doing the same for mouse clicks.
Am I even thinking about the problem in the correct mindset?

I managed to solve the UI touch input issue by making separate child nodes of the Control Node Buttons that are TouchScreenButton Nodes and they use an invisible texture. However, as they are not control nodes, but rather Node2D, their size can mismatch that of their parent button, so manual resizing via code is required.

I’d still love to know if there is a better way to go about this, so if anyone has any ideas, please share!

EDIT: Another way I found to make touch work inside menus without placing TouchScreenButtons over every click-able thing (which would be insane), is to run “Input.set_emulate_mouse_from_touch(true)” when entering a menu, and set it to false when entering the game.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.