How InputEvent works

Godot Version

4.3stable

Question

There are two area2D in my test scene, area1 and area2.
Once they receive mouse click event, message will be printed:


When I click the shared part of these two area, I think the area2 which is belower in the tree will receive the event first, so the output will always be ‘area2 is clicked’. But it seems the result is random:
“2:Left Mouse Button
1:Left Mouse Button
1:Left Mouse Button
1:Left Mouse Button
1:Left Mouse Button
1:Left Mouse Button
2:Left Mouse Button
1:Left Mouse Button
2:Left Mouse Button
2:Left Mouse Button
2:Left Mouse Button
1:Left Mouse Button
2:Left Mouse Button”
That is confused.

Visually one area2d is rendered after the other and looks like it is “on top”, but that is just a rendering order illusion, and the mechanism governing the detection is the collision system.

When two areas in the same collision layer overlap, it cannot be deterministically determined who should be picked. This is why it seems like it’s random, because it is non-deterministic.

Looks like using area2d is not a good idea to detect and organize inputevents. I’ll change to another way. Thanks for your replying.

I have helped someone trying to make a card game using control nodes with hover events. There is no easy solution.

This may be of interest to you

Maybe they were just areas too. Although devjac is trying to make a card game. I think he exploded using control nodes…

Also if you haven’t seen this doc, it explains how input events works.

In your case object picking.

You can enable object picking sorting but it has its limitations. More info here Viewport.physics_object_picking_sort

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.