godot: Button is not pressed by InputEventScreenTouch when Emulate Mouse From Touch is disabled in the Project Settings

Godot version: 3.0.6

OS/device including version: windows 10 pro / GT 1030 gpu

Issue description: In the script extending button, when using _gui_input() and InputEventScreenTouch, it does not cause the button to be pressed down. Visually also the button does not go button_down.

Steps to reproduce: Create a button, and in the code do:

func _gui_input():
   if event is InputEventScreenTouch and event.is_pressed():
       self.pressed = true

// Also if you connect the pressed() signal with this button, it will not trigger the signal when self.pressed = true. Visually the button does not go down and it does not trigger the Pressed() signal. HOWEVER, IF THE BUTTON IS SET TO TOGGLE MODE, IT WILL REGISTER THE BUTTON AS PRESSED CORRECTLY

Minimal reproduction project: InputEventScreenTouch Bug.zip

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 4
  • Comments: 43 (22 by maintainers)

Commits related to this issue

Most upvoted comments

I think UI controls not working with touch controls is a problem.

There is a option Emulate Touchscreen at Project Settings > Display > Window > Handheld to test touches on PC. doesn’t it help to test on PC?

Yes. You’re right. However, I do not consider that a reliable way to test your input, because although it’s emulating a touch, there are slight discrepancies which could affect the behavior. For example, after pressing and holding your finger down, if you move it at all, godot interprets that as a release, I think. It’s behaving very strangely and I can’t get it to work.

I think UI controls not working with touch controls is a problem.

I agree with you. I was just worried maybe I was wrong and I looked dumb. I am pretty sure when I look back though, it really wasn’t working properly as it should.

This issue explains why I couldn’t get SplitContainers working on Android when Emulate mouse from touch was disabled. Are Control nodes really not useable with touch input? This seems like a massive oversight given how expansive and full-featured the UI building nodes are in Godot. Surely using multi-touch in combination with UI isn’t that rare a use case? TouchScreenButton is obviously useful for buttons, but what about all the other Control nodes?

Also is this documented anywhere? I can’t recall seeing mention in the documentation of requiring Emulate mouse from touch to be enabled to use Control nodes in your project.

I’m interested in letting mobile users press multiple buttons at once, which I suspect is impossible with “Emulate Mouse From Touch”.

Look into using TouchScreenButton nodes for this use case (instead of Button).

the InputEventScreenTouch is occurred once only touch start or end. when holding down, InputEventScreenDrag event occurs.

if you want to check it, I would suggest you to use a variable to save its state.

var is_touched = false
func _gui_input():
    if event is InputEventScreenTouch:
        is_touched = event.is_pressed()

does it help?

I have same/similar issue. I switch off “emulate mouse from touch” so that I can handle selecting objects in 3D space by tapping on them (collision shape + _input_event function). That works, but I now can’t use any of the standard UI controls. Not even LineEdit.

I’m not sure if this observation and tighter scoping of the issue with worth filing a new GitHub Issue, what do you think?

No need to open a new issue – I think it’s the same underlying issue.

…Buttons should be pressed (and appear to be pressed) automatically when using touch input on mobile, as Emulate Mouse From Touch is enabled by default.

Emulate Touch From Mouse is not enabled by default, but that’s intended to be used for development on desktop platforms anyway.

This actually may be the crux of my issue! I definitely turned off Emulate Mouse From Touch, because I want to be able to grab multi-touch and swipe/drag inputs. I’ve also turned on Emulate Touch From Mouse, and have no issue pressing the buttons while running locally with that option enabled. Did I perhaps misunderstand the intent of the former option?

a flag to detect whether a mouse event is emulated

It looks like this already exists! device in InputEvent is set to -1 (InputEvent::DEVICE_ID_EMULATION internally) when the input is emulated. This seems to be true for both emulated mouse events and emulated touch events, but the docs only mention that this is the case for emulated mouse events, so that should probably be updated.

This allows for a new workaround:

  • Leave “Emulate Mouse From Touch” enabled, and explicitly ignore emulated mouse input in custom controls by checking the device ID

Which is good enough for me.

As said above, support for native touch events was never implemented in most Control nodes. It’s a lot of work to do properly, and mouse emulation is suitable for most projects already. This is especially the case as most Godot developers targeting mobile platforms are creating fairly simple GUIs.

In my case, this falls apart because I’m building a multi-platform game with multiple viewports, which needs to support both touch and mouse, including pinch zoom on touch devices. I had hoped to leverage the rich UI library offered by Godot, but it seems that in order to do this I either need to take away multitouch functionality or build my own UI controls from scratch.

I imagine I’m not alone in wanting to use a rich UI in combination with multitouch gestures, but perhaps most users aren’t building for multiple platforms.

While this is still a problem, I have worked around it myself by leaving “Emulate Mouse From Touch” enabled and capturing mouse events instead. I can capture the swipes I’m interested in this way. Probably not good enough if you want to capture multiple finger swipes at the same time, but I’m not doing that.

Hi, I created this ticket like a year or two ago. Been following the updates on this issue. In all fairness, I was pretty new to godot when I first used it. I probably could find a workaround easily now with my experience. Maybe I was just doing something wrong, or maybe it actually was a problem.

Reading the source, it seems to me that indeed there is only mouse integration for button pressing. From the OP:

Visually the button does not go down and it does not trigger the Pressed() signal.

From my own experience, when Emulate Touch From Mouse is off, this is true. The pressed signal is not fired, and no visual element of the button is interacted with. I’m not sure if this observation and tighter scoping of the issue with worth filing a new GitHub Issue, what do you think? It does seem at least loosely related, and even if the behavior is intended, some documentation on the subject would be great. It’s kind of baffling to me that your only option for interacting with menus in Godot on mobile is to emulate mouse behavior.

This might be happening due to touch release events not being sent. Similar to #16761, #41585

This issue should be redefined as an enhancement to the BaseButton class that lets it also detect the InputEventScreenTouch event in _gui_input