godot: Touch events not working on Godot 4.2+ on Android 14 after PR #80644

Tested versions

Reproducible in: 4.3 dev3, 4.2.1 stable Not reproducible in 4.1.3

System information

Godot v4.1.3.stable - macOS 14.3.1 - Vulkan (Compatibility) - Apple M3 Pro - Apple M3 Pro (12 Threads) (Have been tested on older Mac with Intel silicon)

Issue description

I am creating a small mobile game. I am using https://github.com/Federico-Ciuffardi/GodotTouchInputManager. I updated Godot from 4.1.3 to version 4.2.1 and touch events stopped working. First I thought that problem was in that asset but then I tested godot native events and they didn’t work either.

In included demo project it detects for example touch and drag in 4.1.3 but in 4.2.1 it only detects left mouse button and mouse motion. I have tested it in both emulator and on physical device.

I went through change log and didn’t noticed any breaking changes that should affect this.

Steps to reproduce

I created a clean project and added one small script

extends Node2D

@onready var label = $Label

func _input(event: InputEvent):
	label.text = event.as_text()
	if event is InputEventScreenTouch:
		var touch_position = event.position
		var label_node = Label.new()
		label_node.text = "Touch"
		label_node.position = touch_position
		add_child(label_node)
	elif event is InputEventScreenDrag:
		var touch_position = event.position
		var label_node = Label.new()
		label_node.text = "Drag"
		label_node.position = touch_position
		add_child(label_node)

Minimal reproduction project (MRP)

Whole project can be downloaded from: https://drive.google.com/file/d/1-2dK2HoJXY93pOmdzj7exX7wlihuFy_y/view?usp=sharing

About this issue

  • Original URL
  • State: open
  • Created 4 months ago
  • Reactions: 4
  • Comments: 19 (7 by maintainers)

Most upvoted comments

I have tested the MRP on an emulator with both an Android 13 and an Android 14 image. For me the bug happens on both Android versions.

To me it looks like a behavior of the emulator that adds SOURCE_STYLUS to eventSource.

@Sauermann @devantti

I installed Android Studio, tested it using the emulator, and was able to reproduce the error. To be more direct, it seems that the error only occurs in the emulator (QEMU: https://developer.android.com/studio/run/emulator).

Edited: I can also confirm that v4.1.4.stable.official ([fe0e8e557]) does not have this error in the emulator, work fine, see:

image

I have tested the MRP on Debian Linux and exported it to an Android 13 device with the following Godot versions

I was unable to replicate the behavior indicated in the screen recording above. For me dragging on the Android device has the effect, that “Drag” and “Touch” Labels are created.

@grumpOldman from what Operating System did you export the MRP? I would like to find out, why I can’t replicate this problem.

It was built/exported on Windows 10

Apologies, I can’t remember the exact circumstances around the removal of that line, but I remember it was affecting stylus events in some way.

I have investigated the difference of behavior, when running the MRP on the emulator and on a Sony Android 13 device.

The behavior differs for this code section:

https://github.com/godotengine/godot/blob/6118592c6d88350d01f74faff6fd49754f84a7d0/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java#L447-L453

  • On the hardware device: eventSource = 4098 (0x1002)
  • On the emulator: eventSource = 20482 (0x5002)

Looking at https://developer.android.com/reference/android/view/InputDevice we get the following difference between the input events sent from the emulator/device:

Event source Emulator Hardware Device
SOURCE_CLASS_POINTER (2^1, 0x2) yes yes
SOURCE_TOUCHSCREEN (2^12, 0x1000) yes yes
SOURCE_STYLUS (2^14, 0x4000) yes no

So it looks like the comment https://github.com/godotengine/godot/pull/80644#discussion_r1297848312 was justified and the change of that PR introduced this issue.

Without a Pen, I can’t properly test, if changes to the above function will break https://github.com/godotengine/godot-proposals/issues/735

@Sauermann: Exported my project to Android on Godot v4.2.2.stable.official [15073afe3] with both use gradle build set on and off. Tested on Samsung Galaxy S23 (SM-S911B/DS) with Android version 14 and it didn’t work.

I did also double check and exported Godot v4.1.4.stable.official [fe0e8e557] and it works on same device.

@Sauermann I’m using Windows 10 to generate the APK.

But keep in mind that I’m not building locally, I’m generating the APK from the export template (mirror: https://github.com/godotengine/godot/releases/download/4.2.2-stable/Godot_v4.2.2-stable_export_templates.tpz), so the operating system probably won’t influence it.

I suspect that the OP’s problem is some UI element in his game, or that he is testing on the emulator and maybe there is some configuration in the emulator that is conflicting.

Note: I also tried using project.config the same way as the OP, but I couldn’t reproduce the error on device, details:

config_version=5

[application]

config/name="touch-android"
run/main_scene="res://test.tscn"
config/features=PackedStringArray("4.2", "GL Compatibility")
config/icon="res://icon.svg"

[display]

window/size/viewport_width=648
window/size/viewport_height=1152
window/handheld/orientation=1

[input_devices]

pointing/emulate_touch_from_mouse=true
pointing/emulate_mouse_from_touch=false

[rendering]

renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"
textures/vram_compression/import_etc2_astc=true

@devantii using exactly your code in v4.2.2.stable.official [15073afe3]:

extends Node2D

@onready var label = $Label

func _input(event: InputEvent):
    label.text = event.as_text()
    if event is InputEventScreenTouch:
        var touch_position = event.position
        var label_node = Label.new()
        label_node.text = "Touch"
        label_node.position = touch_position
        add_child(label_node)
    elif event is InputEventScreenDrag:
        var touch_position = event.position
        var label_node = Label.new()
        label_node.text = "Drag"
        label_node.position = touch_position
        add_child(label_node)

Running on Samsung M31 device works fine:

https://github.com/godotengine/godot/assets/4368952/7c84fb97-ae28-4216-a2dc-4344d292d859

@devantti created an MRP in version 4.3-dev3, I couldn’t reproduce the problem. Your MRP weighs more than 150MB, I recommend that you create an actual MRP that reproduces the problem, as the problem is possibly not in the “_input”, it could be a UI element that is obstructing something, or another problem, please provide an Minimal reproduction project.