This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes


I can't figure how to visually press a button in GDScript. I want my button to appear pressed, I know how to send the signal that the button has been pressed.

I don't want to use the "ui_accept" action and the button must still work with mouse clic.

Here is my code :

func _input(event):
        if Input.is_action_just_pressed("up_action"):
            $Node2D/Button.pressed = true

The console only print "False" except when I press the button with a mouse clic then trigger the "upaction". The "upaction" contains the Up arrow key and the W key.

Do you know how can I visually press my button though GDScript ?

Thanks !

Godot version 3.4.3
in Engine by (12 points)

1 Answer

0 votes

You have to enable toggle mode. This is the only way for button to have 2 states - pressed and unpressed. Otherwise pressed will be true only for duration of one frame.

If there is some reason You can't have toggle buttons, there is another way around - You can access and change visual aspect of "button_pressed" in your Theme.

by (8,188 points)

There's no other way ? When I press the button with a mouse clic, the button remains pressed until I release the mouse button. Can I have the same result with a keyboard button without using toggle ?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.