Rendering Order vs Rollision Order (2D)

Godot Version

4.2

Question

Hi Godot community!

I’m developing a 2D side-view shooter game, similar to a shooting gallery, where several spawners generate new objects. My challenge is handling click events on overlapping objects correctly.

I currently use _input_event(_viewport, event, _shape_idx) to detect object hits, calling get_viewport().set_input_as_handled() within it to prevent further event propagation.

However, due to objects sharing the same layer and Z-axis, clicks on overlapping objects don’t always register as expected, sometimes affecting objects rendered below the intended target.

I’ve considered a few solutions, such as
a) having objects register hits in an list, which is processed by the GameManger to determine the topmost object while checking the scene tree. One Problem is, that the GameManager has to wait to ensure that the _input_event of all objects is processed. This is odd.

b) I also thought about casting a ray to get the list of elements, but i am not sure if I can cast a ray in z direction for a 2d game.

Could anyone guide me toward a more elegant solution or point out what I might be overlooking? Is my explanation clear?

Thank you for any assistance!!
senexger

You could try enabling Viewport.physics_object_picking_sort

1 Like

Thank you very much! It just works :slight_smile: