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

Input event order for Viewports, Areas doesn't match documentation #68703

Closed
paulmiller opened this issue Nov 16, 2022 · 2 comments · Fixed by godotengine/godot-docs#6396
Closed

Comments

@paulmiller
Copy link

Godot version

3.5.1.stable, 4.0.beta

System information

Arch Linux

Issue description

I think this is a bug, but it's also possible I'm misunderstanding the documentation.

The Using InputEvent tutorial describes this sequence:

  1. Call Node._input() on every Node in reverse order.
  2. Call Control._gui_input().
  3. Call Node._unhandled_input() on every Node in reverse order.
  4. If object picking is on, call Area._input_event() on any picked object.
  5. Repeat for the next Viewport in the tree.

If I understand that correctly, then when clicking the CollisionShape in this scene tree:

  • Spatial1
    • Spatial2
    • ViewportContainer
      • Viewport
        • Spatial3
    • Area
      • CollisionShape

The order of Spatial._input() and Area._input_event() calls should be:

  1. Spatial2._input()
  2. Spatial1._input()
  3. Area._input_event()
  4. Spatial3._input()

But It seems like Viewports receive input events in order with every other Node in the tree, rather than at the end. So the order is actually:

  1. Spatial3._input()
  2. Spatial2._input()
  3. Spatial1._input()
  4. Area._input_event()

I use Godot 3 node names here but the same happens in Godot 4.

The relevant Godot 4 code seems to be SceneTree::_call_input_pause(); it loops over the Nodes, and if a given node happens to be a SubViewportContainer, then Node::_call_input() > SubViewportContainer::input() > Viewport::push_input() > SceneTree::_call_input_pause(), which then loops over the Nodes under the SubViewportContainer.

Steps to reproduce

The attached Godot 3 project has the scene tree I described. Click the sphere and see the order logged in the console.

Minimal reproduction project

input-test.zip

@Sauermann
Copy link
Contributor

Sauermann commented Nov 16, 2022

Yes, the "Using InputEvent tutorial" is outdated. I intend to update it, however there are a few bugfix pull-requests waiting for review (e.g. #58334), that will have an impact on that tutorial, so I would like to update the tutorial after they get merged.

I created this infographic to showcase how event-processing works, which matches your findings:
CurrentSubViewportHandling drawio

@Sauermann
Copy link
Contributor

Sauermann commented Nov 19, 2022

I had a look at this issue and have updated the parts of the tutorial, that will be unaffected by the open PRs.

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

Successfully merging a pull request may close this issue.

4 participants