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
Area2D mouse_entered and mouse_exited signals not called in Viewport #26181
Comments
It seems that all signals from |
That is expected behavior. Picking works with unhandled events and currently You need something like this in your
I'll send a PR that allows to have that working automatically, but I don't think it will do it into 3.1.0. |
I'm using the latest version. It's still not working |
@RandomShaper can we reopen the issue to track it? I just ran into the same issue and it doesnt seem obvious as to the end user why this would not work. |
@giulianob indeed. It took me a lot of asking around for a problem that had no obvious solution, until I figured this ought to be an issue. In my case it involves 3D Areas. Thanks for that workaround @RandomShaper. |
@RandomShaper I don't understand, in your example code you used Also, if I click an Area2D inside a viewport, and the area doesn't react, what exactly is handling that input? And how to make sure it gets forwarded to that viewport and not to some other random script in the game that might have |
@Zylann , I did have to turn input on/off manually for the viewport, using I suppose this is also related to your other concern, since the input I'm using in the scene that's under the viewport is actually Area |
I still can't get it to work. I tried the workaround and v3.2 alpha (someone else had mentioned that it was working in it). Perhaps I am not setting it up correctly? |
It's a little hack but it helped me.
|
I still cannot get mouse_entered/exited signals to fire either inside a viewport of a viewportcontainer. Edit: |
Investigated this deeper today:
This has several flaws:
So if you have a viewport with some items, and you'd want clicking somewhere on the viewport but not on an item to trigger something, the only solution is to have another area behind those objects (from the camera POV) that gets picked. And when that happens, you can do things (possibly send an input event 'behind' for example). I have to say, because object picking happens during physics processing, I can't see an easy fix to this (not a godot dev though, so perhaps you guys have an idea already). EDIT: also for the record, I think it's better to do hack the viewport container over the viewport, otherwise all inputs go through the viewport, meaning even clicks outside the viewport-container area can trigger picking. So do this instead in the ViewportContainer script:
|
I've got a similar issue with the latest version 3.2.1.stable.official of Godot, I tried the hack with the |
Same issue on 3.2. Connecting the |
Just faced the same problem, but instead of a viewport it was a edit: noted it's not working properly since now each processed frame the edit2: Input page says the Following :
however I can't find any properties Area related to activate this callback reception. |
Still broken. The workaround does not work. _input_event never fires for an CollisionObject2D node in a viewport. This bug (yes, it's a bug) makes it impossible to select a unit, building, city, etc... by clicking on it. |
I will add my voice that this seems like a bug or at the least like a very unintuitive issue. There's no reason why a Viewport would be handling input events for children nodes if the ViewportContainer has its mouse_filter set to ignore. It makes even less sense that it does not appear to be handling events going to control nodes, but only stuff going towards Area2D/CollisionShape2D. So having a mouse_entered() signal on a Panel will work, but the mouse_entered() signal on an Area2D parent of the same panel will not work. Even more frustratingly, I don't understand how changing the _input to an _unhandled_input on the viewport script would help. The _input event is anyway received by the Area2D and CollisionShape2D node inside the viewport, it just doesn't trigger the relevant mouse signals of the CollisionShape2D. One would have to manually recreate the mouse signal logic by hand inside the _input(), no? |
2020 and still the same problem |
I've lost about two days with this issue and have finally been able to solve it. What finally clicked for me was wraitii's comment, in particular:
I'm not entirely sure this solves the issue, it may not for others, but it did for me. This may not be a very frequent situation, since it requires handling viewports and mouse input, which I suspect is unusual in game development with Godot. But it should be much more well documented regarding the solution. I'd be happy to contribute but I have no clue where to do it. If someone can point me to the right direction I'd write a few lines in the documentation about this. |
See Contributing to the Class Reference with Git 🙂 You want to modify |
I also had the same issue and got it fixed thanks to #26181 (comment). And what @jdferreira said in #26181 (comment) is also important. My issue was in a 3d viewport. All this meant to me that as soon as you use a viewport, handling inputs in it becomes impossible if you don't know what's going on, that is if you don't read this issue. I don't have enough knowledge about this stuff, but it seems to me that a viewport container should forward automatically unhandled inputs to a child viewport, what's the point of blocking them? |
I had the same issue with an Area3D node but none of the suggested workarounds have worked for me. I have a a ViewportContainer with a Viewport child, and the Viewport has a child of a MeshInstance which has a camera setup and some nodes (Area3D) that I want to check if the user clicks on. Using the |
After about 3 months of struggling with this on and off, jdferreira's fix worked for me. Mainly, make sure "Object Picking" under "Physics" in your viewport is checked. I had the rest of the system setup, and now it works fine. |
It's working with current head : 59b6950 |
I totally agree. Inputs could even only be propagated when This may not be a usual situation in games, but I'd guess it is for desktop/web tools with mouse input. |
It found a work around, prioritizing units Area2d over map Area2D boardgame-map |
@jdferreira Can you please explain which node do you refer to as parent? The parent of the |
Hello,I have a similar problem.
It worked well on PC. |
To make @RandomShaper's workaround more clear: I've been using this setup for a while, and so far it seems to work fine for me. This is the scene tree:
I have a script on the ViewportContainer and another on the Viewport. Then I connect extends ViewportContainer
onready var viewport = $Viewport
func _on_ViewportContainer_mouse_entered() -> void:
viewport.set_process_input(true)
func _on_ViewportContainer_mouse_exited() -> void:
viewport.set_process_input(false) (To be honest, at this point I can't quite remember if the code above is strictly needed. Still, one other issue that it solved for me, was that it prevents input from happening at all in the viewport when I'm using other parts of my app, which in my case is what I want.) And then on the viewport I relay the input as @RandomShaper suggested, but only if it's mouse input. This is because keyboard input seems to go through on its own, and doesn't need to be relayed here. I found this when I noticed my extends Viewport
func _input(event: InputEvent) -> void:
if event is InputEventMouse:
unhandled_input(event) There may be other kinds of input events that need to be relayed too, but I only know about mouse events. |
This seems to work without the workaround if you set ViewportContainer -> Viewport -> Area.input_event signals will fire. Feels backwards but it makes sense if you read the thread :D |
邮件已查收~ ( *^o^* ) つロ 乾杯~
|
This is a duplicate of #17326. |
Godot version:
Tested with 4f697f7
OS/device including version:
Linux Mint 19.1 tessa 64 Bit
Issue description:
When using Area2D in a Viewport the mouse_entered and mouse_exited signals are never called.
Steps to reproduce:
Use the test project.
When you run the project you see two godot-icons. Both icons are unmodified instances of
Area2D.tscn
.The one on the left is contained in a Viewport and does not print any messages when it should receive mouse enter and exit signals.
The one on the right will print messages when the mouse enters/exits the icon.
Additional info:
The UI node's mouse filter is set to
pass
.The ViewportContainer node's mouse filter is set to
pass
.The Viewport's setting
Handle input locally
was tested enabled and disabled.The Viewport's setting
Disable input
is disabled.The Viewport's setting
Own World
was tested enabled and disabled.Minimal reproduction project:
ViewportIssue.zip
The text was updated successfully, but these errors were encountered: