Physics2D.GetRayIntersection vs. Sprite Renderer - Order in Layer

Does the Physics2D.GetRayIntersection method take the ordering layer into account?

It seems like it does not.
I have a bunch of sprites on top of each other all with different ordering layer value so they appear above each other.
What I can do is select a sprite and give it a highest ordering layer so it then moves onto the top.

The problem I have is that when I click on a sprite (that’s on the top) it quite often will select another sprite that is under it (has a lower ordering layer value)
Why is this?

It would be pretty disappointing if the Physics2D.GetRayIntersection wouldn’t take the ordering layer into account, then you would have to change the Z depth of the sprites slightly to make a workaround.

Please explain.
Br,
Peter

It probably wouldn’t as one is Physics related and the other is display related. Layer order only affects the order of rendering, not the actual physical location. Z-depth (or layer masking) is how you want deal with physics raycasting.

Yeah that’s totally understandable but still when using Unity 2D shouldn’t you be able to do everything without “clowning around” with the Z Depth when there are layers and also order in layer?
All the information is already there, why isn’t there a switch or something: “take order in layer into account also” after doing raycasting.

You write: “you want deal with physics raycasting”
Is there a display order related raycasting? Some way to select the top most displayed sprite?

Br,
Peter