-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
Two overlapping Area2D / pickable CollisionObjects both receive input event #29825
Comments
That's expected. The signals have already been emitted so the event can't be set as handled. If you need more control over it you'll need to use |
It seems to me that Area2D should have some kind mechanism to be able to click just the top most |
For some time I am searching the web trying to find generic solution for this, but I only find people with similar question. |
I wrote this code and it seems to work in my case, but I do not know if it will work for all cases. Still i think Area2D should do this out of the box.
|
I have also ran into this issue, so I though I would share my own workaround: var mouse_entered = false
func _unhandled_input(event):
if event.is_action_pressed("mouse_left_click") && \
mouse_entered:
# do here whatever should happen when you click on that node
self.get_tree().set_input_as_handled()
func _on_Area2D_mouse_entered():
mouse_entered = true
func _on_Area2D_mouse_exited():
mouse_entered = false
Here I only use Area2D signals to check if the mouse is inside the CollisionShape2D. The input event is handled directly by the node without emitting any signals. |
I'm having the same issue and I think that Area2D should have a machanism to mask the input of the other Area2D items below. @Winsalot thanks for the workaround! However how can I know the order in which the areas are clicked? As far as I can tell if I click on an area the order of input is random, correct? |
looks like a duplicate of #16042 and has more detail info |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Please don't bump issues without contributing significant new information. Use the 👍 reaction button on the first post instead. |
@Calinou can I give a gentle nudge on PR review for this? |
Godot version:
3.1
OS/device including version:
Windows 10
Issue description:
I have two overlapping Area2d with rectangle shape. When I click them, both got input event. The one at the bottom gets the event first.
So there is no way to just click the top one. Moreover the get_tree().set_input_as_handled() doesn't stop propagating this event.
Minimal reproduction project:
godotArea2dOverlapping.zip
The text was updated successfully, but these errors were encountered: