• 2D
  • My Touch Input (Android) suddenly stopped working after building

I had written a code which was working perfectly but suddenly it stopped working. Still works when I emulate mouse touch in my PC.

Here is the code

extends Node

var touch_col
var is_active = false

var evt

func _ready():
	touch_col = get_child(0).get_child(0)
	touch_col.disabled = true
	
func _process(_delta):
	if evt != null:
		get_node("TouchInput").global_position = evt.global_position

func _input(event):
	evt = event
	if event is InputEventScreenTouch:
		print("OK")
		is_active = !is_active
		if is_active:
			touch_col.disabled = false
		else:
			touch_col.disabled = true

I actually don't know what you want to achieve with "is_active".

InputEventScreenTouch has an attribute "pressed". Maybe use that? There's also the attribute index which indicate which "#paralleltouch" that specific event is for. So when touching with two fingers there maybe overlapping touchevents pressed=true -> pressed=false with different index values. Maybe save the index of the first pressed=true event and only react to pressed=false when the event index matches or something similar.

You save any event from input for use in process. Maybe you should save only InputEventScreenTouch events (put evt=... inside the if). And maybe only save the position.

@wombatstampede said: I actually don't know what you want to achieve with "is_active".

InputEventScreenTouch has an attribute "pressed". Maybe use that? There's also the attribute index which indicate which "#paralleltouch" that specific event is for. So when touching with two fingers there maybe overlapping touchevents pressed=true -> pressed=false with different index values. Maybe save the index of the first pressed=true event and only react to pressed=false when the event index matches or something similar.

You save any event from input for use in process. Maybe you should save only InputEventScreenTouch events (put evt=... inside the if). And maybe only save the position.

Hey, thanks for answering. I actualy need is_active for my other script. This script worked fine until recently. It still works when I emulate touch screen in godot.

Here are some errors that are shown whn I build the game.

Unicode error: invalid skip Unicode error: invalid skip Unicode error: invalid skip Unicode error: invalid skip Unicode error: invalid skip Unicode error: no space left

I ran logcat and god this error

10-29 22:46:32.014 13717 13738 E godot : SCRIPT ERROR: Invalid get index 'global_position' (on base: 'InputEventScreenTouch'). 10-29 22:46:32.014 13717 13738 E godot : At: res://Scripts/InputManager.gdc:15:_process() - Invalid get index 'global_position' (on base: 'InputEventScreenTouch').

get_node("TouchInput").global_position = evt.global_position // line 14 of input script

Hey, I was able to solve it. Just had to change global_position to position in line 14

To say it again: I propose that you move evt=event two lines lower inside the if block unless you want process to actually work on every (even non-touch) event that triggers input().

@wombatstampede said: To say it again: I propose that you move evt=event two lines lower inside the if block unless you want process to actually work on every (even non-touch) event that triggers input().

I will do that :-)