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

Mouse input events not being detected from Area2D inside a SubViewport unless a key is pressed #84258

Closed
lazaromenezes opened this issue Oct 31, 2023 · 13 comments · Fixed by #87385

Comments

@lazaromenezes
Copy link

Godot version

v4.2.beta4.official [93cdacb]

System information

Godot v4.2.beta4 - Windows 10.0.23570 - Vulkan (Mobile) - dedicated NVIDIA GeForce RTX 3060 (NVIDIA; 31.0.15.5009) - AMD Ryzen 5 5500 (12 Threads)

Issue description

Testing my 4.1.2 project with 4.2-beta 4 I noticed this behavior that might be related with the changes within subviewports and event handling. I'm not sure if any of the issues mentioned by #83276 is really similar to this so decided to open a new issue.

It seems that mouse events are not being sent to an Area2D that's a child from a sub view port, unless some other event is fired up into the main viewport before.

In the screen recording bellow, 'D' is a direct child from my root scene node while 'S' is inside a Subviewport

subviewport_mrp.DEBUG.2023-10-31.13-31-46.mp4

This is the setup:

image

The mouse_entered and mouse_exited events are captured properly by the direct child scene "D" while the events only has effects in "S" if other event is fired before. Per exemple, start a click in "D" and drag until "S" or hold any keyboard key pressed and hover over "S", then the mouse_entered and mouse_exited work.

Steps to reproduce

Using the given MRP:

  1. Load the main scene
  2. Hover over the tile "D", it should become green;
  3. Exit mouse from the tile "D", it should be back to its original color;
  4. Hover over the tile "S", it was supposed to become green, but it is not;
    4.1) Hold any keyboard key and hover the tile "S", it becomes green.

Minimal reproduction project

subviewport_mrp.zip

@AThousandShips
Copy link
Member

To confirm, this behaviour is not present in 4.1.2?

@lazaromenezes
Copy link
Author

It is not. It works fine for both the MRP and my full project. I can say it was also not working in "4.2-beta 2" but I couldn't investigate further at the time so I don't know if the missbehavior is exactly the same as I'm reporting now.

@lazaromenezes
Copy link
Author

I was going to test the build for #83276 but it's expired :(

@Sauermann
Copy link
Contributor

From a quick peak at the MRP, this might be more related to #81287 than to #83276.

@kitbdev
Copy link
Contributor

kitbdev commented Nov 1, 2023

#83276 is just about Control nodes, so it probably wouldn't have fixed it.
This might still be related to #67791 though.

@Sauermann
Copy link
Contributor

I have bisected this bug and it got introduced in #48800.

@KeTr
Copy link

KeTr commented Nov 25, 2023

Is my understanding correct, that this issue is the reason, I'm unable to get MouseEntered and MouseExited Signals (on Area2D) to work inside a SubviewPort? ObjectPicking is on and the Container has Mouse-Filter set to "Pass". This works fine on 4.1.2.

I just stumbled on this after my first try to upgrade to 4.2-rc1 (from 4.1.2), but this makes 4.2 completely unusable for me.

@Sauermann
Copy link
Contributor

@KeTr Your assessment is correct. Fortunately the reason for this problem is well known: currently there are two different methods implemented in different places of the source code for determining, if an InputEvent has already been handled.
A PR is already available, that intends to resolve this issue. But because of the feature-freeze, the fix will not make it into 4.2.
If you want to help getting the fix included in 4.3, feel free to test the linked PR and comment, if it solves your problem.

@KeTr
Copy link

KeTr commented Nov 25, 2023

@Sauermann Thanks for the confirmation. I had a cursory look over the commit, that introduces this issue as well as both proposed fixes, but to be honest I'm still a Godot beginner and didn't entirely understand what's going on. So I'm gonna ask here: Is there any workaround (aside from polling the GlobalMousePosition every frame.... instead of using the broken signals) for this, or does this mean, I just have to skip 4.2 entirely if I depend on this?

@Sauermann
Copy link
Contributor

As a very crude workaround (which introduces other issues for example when setting the event to handled within the SubViewport) you could do the following:

  1. Attach a GDScript to the SubViewportContainer.
  2. In this script, override the _input-function in which you set the SubViewports handle_input_locally to true:
func _input(_event):
	$SubViewport.handle_input_locally = true

Here is the original MRP with this change: subviewport_mrp_workaround.zip

@lazaromenezes
Copy link
Author

Hello, I had to step back for a couple of weeks but it looks like #85665 fixes this issue? Is there a build already I can test? I noticed it was merged into 4.2 branch but I actually got confused if it made it to the latest 4.2 release or not.

Thank you!

@Sauermann
Copy link
Contributor

#85665 is available in v4.2.1

@lazaromenezes
Copy link
Author

I was finally able to check this up within my project and confirmed it's working for v4.2.1 now :)

Thank you for all the work.

By the way, since v4.3.dev2.official [3524346] is out there I gave it a try and the problem is present, but I'm assuming some fixes weren't merged yet, but wanted to give the heads up.

Thank you again.

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.

6 participants