I have problems with inputs of my gamepad, it's executing a function two times every click.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fagnerln

I created a small script for move an Area2d on a grid, I want that the player taps the direction they want to move. If I control it at the keyboard it works flawlessly but for some reason, on the gamepad it execute two times I have no idea why:

const TILE_SIZE = 64

func _input(event):	
    if Input.is_action_just_pressed("ui_up"):
		move_cursor(  0 , -1 )
	elif Input.is_action_just_pressed("ui_down"):
		move_cursor(  0 ,  1 )
	elif Input.is_action_just_pressed("ui_left"):
		move_cursor( -1 ,  0 )
	elif Input.is_action_just_pressed("ui_right"):
		move_cursor(  1 ,  0 )

func move_cursor(x , y):
	cursor.position += Vector2(x , y) * TILE_SIZE
	cursor.pos += Vector2(x , y)

So I tried:

if Input.is_action_pressed("ui_up") and not event.is_echo():

and (I don’t think that make difference):

if Input.is_action_just_pressed("ui_up") and not event.is_echo():

and:

if Input.is_action_just_pressed("ui_up") and event.is_pressed():

In every scenario the keyboard works well, I didn’t changed anything on the input map as it just a prototype, ui_up for example is up on the keyboard and d-pad up.

I’m on linux, using a X360 gamepad

Maybe I should create a Issue on their github or maybe on SDL?

For future reference, this was cross-posted to GitHub: My gamepad d-pad is executing is_action_just_pressed twice · Issue #45443 · godotengine/godot · GitHub

Calinou | 2021-01-25 17:25

:bust_in_silhouette: Reply From: alexass212

you might be calling the function twice perhaps also we need to see the whole script to better help you out, and no I’m no export. also, have you tried adding a return?


   func _input(event): 
    if Input.is_action_just_pressed("ui_up"):
        move_cursor(  0 , -1 )
       return 
    elif Input.is_action_just_pressed("ui_down"):
        move_cursor(  0 ,  1 )
        return 
    elif Input.is_action_just_pressed("ui_left"):
        move_cursor( -1 ,  0 )
        return 
    elif Input.is_action_just_pressed("ui_right"):
        move_cursor(  1 ,  0 )
        return 

There’s nothing calling this function that are related to the gamepad, I created a new project only with this code and the bug remains. I really think that’s a bug on the engine.

fagnerln | 2021-01-25 12:47