Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buttons don't react to "ui_accept" via a mouse button and the cursor not over the control. #64176

Closed
michael-nischt opened this issue Aug 9, 2022 · 8 comments

Comments

@michael-nischt
Copy link

Godot version

v3.5.stable.official [991bb6a]

System information

Arch Linux, NVIDIA GeForce RTX™ 3080 Laptop GPU, GLES3

Issue description

Buttons (or probably any controls) don't react to "ui_accept" via a mouse button with the cursor is not over the control.

This happens with the left mouse button added to the "ui_accept" action list (project settings > input map) or if the button triggers a fake InputActionEvent:

if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and not event.is_pressed():
  scene_tree.set_input_as_handled()
  var evt = InputEventAction.new()
  evt.action = "ui_accept"
  evt.pressed = true
  Input.parse_input_event(evt)
  evt.pressed = false
  Input.parse_input_event(evt)

Other triggers like the keyboard ENTER key still work fine.

It seems to be a regression as it mouse buttons as "ui_accept" worked just fine in v3.4.5.stable.official [f9ac000d5].

Note: The issue required as to revert back the godot version since we hide the cursor and use mouse clicks as "ui_accept" in addition to game-pad inputs.

Steps to reproduce

  1. open the attached minimal reproduction project
  2. run the project
  3. click anywhere in the window besides the button

In Godot v3.5 nothing happens despite a triggered "ui_accept" event.
In Godot v3.4.5 it works as expected.

Note that "ui_accept" bindings (ENTER key) work fine in both versions

Minimal reproduction project

LMB_ui-accept_bug.zip

@Calinou
Copy link
Member

Calinou commented Aug 9, 2022

@michael-nischt Can you reproduce this in any of the 3.5 betas and RCs to determine when the regression started?

@michael-nischt
Copy link
Author

michael-nischt commented Aug 9, 2022

sure,

In RC5 it's still good v3.5.rc5.official [ae6059793] ✔️
In RC6 the issue present v3.5.rc6.official [f05cecdc4]

Based on the RC6 change-log I figured that is related:

In 3.4, input accumulation was mistakenly turned off, and we only realized this regression after 3.4 had had multiple maintenance releases. In this build we turned it back on by default, which should be beneficial for most projects, aside from those that need very precise input (multiple mouse motion events per frame). You can toggle it with Input.set_use_accumulated_input().

And indeed, if i call at the start calling Input.set_use_accumulated_input(false) everything works again.

However, I believe it's still a bug since it's not only a problem with the generated action but also just adding LMB to "ui_accept" in the project settings.

@akien-mga akien-mga added this to the 3.6 milestone Aug 9, 2022
@michael-nischt
Copy link
Author

michael-nischt commented Aug 9, 2022 via email

@RandomShaper
Copy link
Member

The issue when input accumulation is enabled is expected, but we hadn't do a good job so far of letting users know the rules. Namely, you shouldn't send the same input event object multiple times during the same frame. It's not guaranteed to work as expected. It will in some scenarios (no input accumulation, OS layer does not use buffering, etc., etc.; check #64423 for more info). Therefore, the guideline is to instantiate a new event object. That will work always.

@RandomShaper
Copy link
Member

@michael-nischt, can you tell me if the issue about LMB not triggering ui_accept happens in 3.4.5 as well?

@michael-nischt
Copy link
Author

yes, I can confirm:

Adding LMB to "ui_accept" to trigger a focused button is not woking in 3.4.5 either.
(minimal sample LMB_ui-accept_bug_pure.zip)

Faking the "ui_accept" as in original sample with Input.set_use_accumulated_input(false) works on both versions.
(ofc you don't need to in 3.4.5 as it's the default there.)


Just to be clear:

Supporting the LMB in the "ui_accept" list (input map) is not that important to us specifically.

We will continue to fake it likein the original example since we only want this behavior when the mouse cursor in captured.

Of course, it would be preferrable if that would work without setting Input.set_use_accumulated_input(false).
Am I right assuming that the LMB added to "ui_accept" not working is the cause for this? Or are those unrelated?

@RandomShaper
Copy link
Member

RandomShaper commented Aug 15, 2022

They are unrelated.

If you change your script to look like this, it will work regardless the Godot version and status of event accumulation:

if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and not event.is_pressed():
  scene_tree.set_input_as_handled()
  var evt = InputEventAction.new()
  evt.action = "ui_accept"
  evt.pressed = true
  Input.parse_input_event(evt)
  evt = InputEventAction.new()
  evt.action = "ui_accept"
  evt.pressed = false
  Input.parse_input_event(evt)

The other issue, LMB not being able to trigger ui_accept is a separate issue that needs to be fixed in Godot. You may want to open an issue about that specifically and close the current one as solved if the updated script works (it does).

@michael-nischt
Copy link
Author

Oh this is awesome. Thanks so much for adding the clear warning for future versions and the super clear working example! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

4 participants