Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
devantti opened this issue Feb 21, 2024 · 22 comments · Fixed by #92133
Closed

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

devantti opened this issue Feb 21, 2024 · 22 comments · Fixed by #92133

Comments

@devantti
Copy link

devantti commented Feb 21, 2024

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

@brcontainer
Copy link

@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.

@devantti
Copy link
Author

Updated MRP to original message, removed android folder.

@devantti
Copy link
Author

devantti commented Feb 21, 2024

Screen recording from emulator:

Screen.Recording.2024-02-21.at.13.28.02.mov

@devantti
Copy link
Author

devantti commented Mar 9, 2024

Any ideas how to fix this?

Booted up finally my Windows machine too. Installed all the stuff. Tested both MRP and created also a fresh project. And alas still no luck with touch events on mobile.

Godot v4.2.1.stable - Windows 10.0.19045 - GLES3 (Compatibility) - AMD Radeon RX 6800 XT (Advanced Micro Devices, Inc.; 31.0.23013.1023) - AMD Ryzen 5 5600X 6-Core Processor (12 Threads)

Does it matter what SDK version I have installed. First installed just what came with Android Studio and then by following the instructions at https://docs.godotengine.org/en/stable/tutorials/export/exporting_for_android.html:
sdkmanager --sdk_root=<android_sdk_path> "platform-tools" "build-tools;33.0.2" "platforms;android-33" "cmdline-tools;latest" "cmake;3.10.2.4988404" "ndk;23.2.8568313"

@grumpOldman
Copy link

I've tested _input and _unhandled_input in both 4.2.1 and 4.3 dev4. Exported APK tested on device Google Pixel with android 13.

InputEventScreenTouch doesn't work for me either.

@devantti
Copy link
Author

devantti commented Apr 24, 2024

Tested with new versions of Godot. Touch works on 4.1.4 but not on 4.2.2 or 4.3 dev 5.

@Sauermann
Copy link
Contributor

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.

@devantti
Copy link
Author

Could Android studio version and other Android libraries affect if it works or not?

@brcontainer
Copy link

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

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:

video4999357226922542972-1.mp4

@Sauermann
Copy link
Contributor

@brcontainer what operating system do you use?

@brcontainer
Copy link

brcontainer commented Apr 27, 2024

@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

@brcontainer
Copy link

brcontainer commented Apr 27, 2024

@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 ([fe0e8e5]) does not have this error in the emulator, work fine, see:

image

@Sauermann
Copy link
Contributor

I can confirm the bug on Linux when exporting the project to an emulator.

@devantti You have mentioned, that you experience this bug also on a physical device. Can you please verify this and tell, on which physical device you experience this bug? Otherwise it looks like this affects only emulators.

I have bisected this bug to #80644 CC @Distantz

@devantti
Copy link
Author

@Sauermann: Exported my project to Android on Godot v4.2.2.stable.official [15073af] 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 [fe0e8e5] and it works on same device.

@Sauermann
Copy link
Contributor

Sauermann commented Apr 28, 2024

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:

private static boolean isMouseEvent(int eventSource) {
boolean mouseSource = ((eventSource & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) || ((eventSource & InputDevice.SOURCE_STYLUS) == InputDevice.SOURCE_STYLUS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mouseSource = mouseSource || ((eventSource & InputDevice.SOURCE_MOUSE_RELATIVE) == InputDevice.SOURCE_MOUSE_RELATIVE);
}
return mouseSource;
}

  • 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 #80644 (comment) 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 godotengine/godot-proposals#735

@Sauermann Sauermann removed their assignment Apr 28, 2024
@akien-mga akien-mga changed the title Touch events not working on Godot 4.2.1 Touch events not working on Godot 4.2+ on Android 14 after PR #80644 Apr 28, 2024
@akien-mga
Copy link
Member

Sounds like we may have a difference in behavior between Android 13 and 14 in this API?

@Sauermann
Copy link
Contributor

Sauermann commented Apr 28, 2024

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.

@Distantz
Copy link
Contributor

Distantz commented Apr 29, 2024

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.

@grumpOldman
Copy link

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

@KingAkrej
Copy link

I can confirm,I have the same problem with Samsung S24, Windows 10, Godot 4.2.2.

@andrewrexo
Copy link

I can replicate the issue on my Pixel 7 Pro running Android 13. However, my Pixel 6A running Android 14 running Android 14 is unaffected. Touch events are sent as expected.

@AlexanderO88
Copy link

I can confirm with my FireHD 8 (2020) and Godot 4.2.2. I just use the Godot Editor on Android and doesn't have export my project yet but with Godot 4.2.2 the touch events doesn't work, with Godot 4.1.4 it works.

m4gr3d added a commit to m4gr3d/godot that referenced this issue May 19, 2024
Prioritize using the event tool type to detect the type of the event, and only use the event source as fallback.

For reference, see https://developer.android.com/reference/android/view/InputDevice#SOURCE_STYLUS

Fixes godotengine#88621
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Very Bad
Development

Successfully merging a pull request may close this issue.

10 participants