Godot: set_pressed in button don't work

Created on 24 Nov 2019  路  10Comments  路  Source: godotengine/godot

Godot version:

OS/device including version:
win7 32bit godot 3.2 beta2
Issue description:
the property set_pressed(value) in base button haven't any effect

for more information you can see my post on this forum
https://godotforums.org/discussion/comment/30367#Comment_30367

documentation

Most helpful comment

but why not make it work with no toggle mode ??

will be more intuitive to manipulate
the interface with an exotic controller or a midi interface

and it's work with toggle mode

All 10 comments

The issue seems to stem from the fact that if toggle_mode is false, set_pressed() will immediately exit and do nothing.
https://github.com/codecustard/godot/blob/f5a2a44b1e6ac0a2e70d11a77bfd122d99ee372d/scene/gui/base_button.cpp#L209-L212
Does set_pressed work if you try enabling toggle mode? set_toggle_mode(true)

The intended use case of set_pressed() might be for toggles. Maybe the documentation should be updated to say "set_pressed" only works for toggle. Or change the behavior to allow set_pressed() to work regardless, even though it would immediately be set to false on the next frame if toggle_mode is disabled.

@codecustard I guess it'd make sense to print an error message when using set_pressed() with a non-toggle button (while also documenting this).

but why not make it work with no toggle mode ??

will be more intuitive to manipulate
the interface with an exotic controller or a midi interface

and it's work with toggle mode

I also fail to see the point in not allowing any button that can be pressed (aka every button ever) to have a pressed state that can be toggled.

@TheSHEEEP What would the button do once it's set to be pressed (and it's not in toggle mode)? Would it stay pressed until it's clicked again?

I would indeed say stay pressed until clicked again (or until set_pressed with false).
There are a bunch of default behaviours possible here, any of them are fine IMO (as long as they are documented).

The only thing that isn't fine is having a set_pressed function that doesn't set the button to its pressed state ;)

@Calinou I think he is suggesting it should do the same thing as clicking and holding it with the mouse. It keeps the down state until you release it.

It should at least perform the same actions as clicking it; fire events, call the virtual methods, change to the down state for the current frame, etc. Currently, we have to simulate an Input event to press a button with code. It would be made easier if set_pressed() worked for non-toggle buttons too.

Actually, if such a function should call triggers is a wholly different question.
Either way, it wouldn't be a problem to disconnect from triggers for a moment if that wasn't desired.

There is disconnect function for this. Pressing the button with code should have the same effect as pressing it with input. In case you are looking just for the visual changes, you can use custom styleboxes.

@hammeron-art If we change the pressed state for a single frame only, the visual change might not be visible at all if the game runs fast enough :slightly_smiling_face:

That's why I asked for the behavior we should follow when pressing non-toggle buttons by code; there's no perfect solution here.

Also, the current BaseButton::set_pressed() function was written by @reduz. It might have been done this way by design, or out of simplicity. I mentioned him as we might want to know whether fixing this can be done without too much trouble.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

testman42 picture testman42  路  3Comments

RebelliousX picture RebelliousX  路  3Comments

ducdetronquito picture ducdetronquito  路  3Comments

n-pigeon picture n-pigeon  路  3Comments

gonzo191 picture gonzo191  路  3Comments