So, I was told that GetRayIntersectionAll returns unsorted array — http://forum.unity3d.com/threads/213405-GetRayIntersectionAll-result-is-not-sorted?p=1432228
But actual rendering order is in SpriteRenderer. So how do I sort 2d colliders if there are no SpriteRenderers on objects (i.e. they are just invisible colliders)? If everything is in z = 0 plane…
It depends on what you mean by “sorted”; it’s up to you to define that.
–Eric
Sorted as they would be in the third dimension.
If I have several 2d colliders their order is not defined?
I assume that all 2d stuff has to be placed at z = 0. Or it’s a common practice to place 2d objects on different layers and that’s how I can figure out order? But if it is, what are SpriteRenderer’s order parameters for.
It seems easier in 3d where you can move stuff using z coordinate.
Nope, you can put them at z = whatever. In fact it’s a good idea, you can do e.g. parallax scrolling easily that way, just don’t use an orthographic camera. However you still need to use sorting layers to make sure the draw order is correct; using z position only may appear to work, but it only “mostly” works and can’t be relied on.
–Eric
I’m sorry, do you mean that 2d sprites are not z sorted when rendered? o.O
They use their own layering system?
They’re z sorted to some extent, but as I said it’s not 100% reliable. Yes, they use their own layering system, that’s what the sorting layer is for. (Plus “order in layer” for sorting within a layer.)
–Eric