I have a scene with multiple Area2D objects that perform an action when clicked. Some of these objects partially overlap others, but the object that is clicked is currently based on the node's position in the tree. This is an issue when the positions and z_indexes of the objects change. I would like to have the clicked object be determined by the object with the highest z_index at the coordinates of the mouse cursor. I read online that this can be achieved by setting the physics_object_picking_sort of the viewport to true. I have attempted to do this by writing get_viewport().physics_object_picking_sort = true in the _ready() function of the scene's root node, but I did not notice a change in behavior. Am I accessing the viewport incorrectly, or should I be going about this a different way?
#Clicking the Area2D with the largest z_index under the cursor
6 messages · Page 1 of 1 (latest)
I have tried putting that line of code in each of the Node2D objects' _ready() functions, but I am still running into the same issue.
Did you also enable physics_object_picking_first_only ?
I tried a few ways now, but every try threw an error, seemingly indicating that property does not exist. I am running version 4.2.2, and the documentation I have does not mention that value.
The only way I can think of to do it for sure would be to create a collider at the location of the click, and return the colliding Area2D with the largest z_index, but that feels like the wrong way to do it.
You're right, this property was introduced with 4.3
You enabled physics_object_picking though?