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

SubViewportContainer processing Key Input Events before other Control-Nodes #81184

Closed
quiyip opened this issue Aug 30, 2023 · 2 comments
Closed

Comments

@quiyip
Copy link

quiyip commented Aug 30, 2023

Godot version

v4.1.1.stable.official [bd6af8e]

System information

Windows 10

Issue description

The docs state that inputs are processed in the order of _input() > _gui_input() > _shortcut_input() > _unhandled_input() > _unhandled_key_input(). However, SubViewportContainer overrides this ordering by propagating all input (key) events at input(). This triggers all input event functions of its child nodes before all other Control nodes, completely messing up the ordering.

This is a continuation of #58334
although this merge fixed the problem when events contain a position, it does not affect key-press events.

(other related issues are #48401 #48368 and #39666)
@Sauermann

Steps to reproduce

  1. Download reproduction project
  2. Run the project
  3. Left-click on the LineEdit to apply focus
  4. Press any button on the keyboard
  5. Watch the wrong order appear in the console

Correct ordering is:
1 2 3 4 5
_input() > _gui_input() > _shortcut_input() > _unhandled_input() > _unhandled_key_input()

But instead, the ordering is 1, 3, 4, 5, 2

SceneTree
image

LineEdit.gd

extends LineEdit


func _input(event: InputEvent) -> void:
	if event is InputEventKey:
		printt(1, "input")


func _gui_input(event: InputEvent) -> void:
	if event is InputEventKey:
		printt(2, "gui_input")

Player.gd

extends Node2D



func _shortcut_input(event: InputEvent) -> void:
	if event is InputEventKey:
		printt(3, "_shortcut_input")


func _unhandled_input(event: InputEvent) -> void:
	if event is InputEventKey:
		printt(4, "_unhandled_input")


func _unhandled_key_input(event: InputEvent) -> void:
	printt(5, "_unhandled_key_input")

Minimal reproduction project

SubViewportContainer key input bug reproduction project.zip

@Sauermann
Copy link
Contributor

Sauermann commented Aug 30, 2023

I believe, that the problem you describe is related to #79235 and got fixed in current master by #79248.

Can you please verify, if your problem is still apparent in Godot V4.2 dev3?

Also please be aware that this order _input() > _gui_input() > _shortcut_input() > _unhandled_input() > _unhandled_key_input() is guaranteed only within a single Viewport.

In your description, you are utilizing different Viewports:

  • root viewport with LineEdit
  • SubViewport with Node2D

So the above order is not guaranteed when comparing LineEdit and Node2D.

@quiyip
Copy link
Author

quiyip commented Sep 1, 2023

Thank you, fixed in v4.2.dev3.official [013e8e3]

@quiyip quiyip closed this as completed Sep 1, 2023
@akien-mga akien-mga added this to the 4.2 milestone Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants