Sprite render order from script

I am making a tool that tints the color of a sprite when clicked in the scene, and I want to make sure that it targets the sprite that is on top in the sorting order. Now that would have been really easy to solve if with just OrderByDescending if it wasn’t for the SortingGroup component that creates its own sorting hierarchy.

I have been juggling how to determine if two sprites are part of the same group so that those should be compared to eachother only and then compare their parent group to other renderers that are outside the group. But I have gotten to the point where it seems stupid and I wanted to ask here if there is a better way.

Is there a better and reliable way to get the actual “in what order are you rendered” from a list of SpriteRenderers without searching up the hierarchy for SortingGroups and trying to reverse engineer what those will in turn pass on to the renderer.