UI button continuous press does not work

Godot Version

4.2

Question

So i have probably one of the dumbest questions.

I have added a button that when held down is supposed to move my character left using position.x += 10
I used the pressed() signal.
And when i run the game and press the button it just moves it 10 pixels. So its acts like if it were using onbutton_down().

pressed only triggered when you button down and up in that button

this just basically add a boolean that has condition trigger
when button down, you set this boolean variable to true
so in the process/physics_process function when this boolean is true, it will add 10px position to your character
when button up, you set this boolean variable to false, so it will not keep adding 10px position to your character because it’s false

1 Like

Which signal am i supposed to use to have a continuous actionwhen held down? I have actually tried all the button signals and non seem to work.

i edited my first reply, i explained it

notice it will be canceled when only button up, you might want to connect mouse_exit signal from button node, so when you hold down the button and suddenly exit the button texture/rect it will cancel the movement by setting the boolean variable to false

If this is on a touchscreen is the mouse stuff relevant? Im working on a mobile with Android on this.
To check if the button is being held downin gdscript can i do this: if(button.pressed == true)
##do action ?

.pressed is a signal, you cant check it like that
and the button_pressed property will need the toggle_mode property to be activated first, but this one still check after click, so i dont think this way will work
just make a boolean variable

here’s the example:

var is_button_down:bool=false
func _process(delta):
	if is_button_down:
		%Object.position.x+=1

func _on_button_2_button_down():
	is_button_down=true

func _on_button_2_button_up():
	is_button_down=false

func _on_button_2_mouse_exited():
	is_button_down=false

GIF:
buttondownmove

2 Likes

Man i feel stupid. Thanks for the help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.