Search Unity

[Feature Request] Custom sorting position for Renderers

Discussion in 'General Graphics' started by PrecisionCats, Jul 21, 2021.

  1. PrecisionCats

    PrecisionCats

    Joined:
    Nov 19, 2017
    Posts:
    40
    Could you please add the option to give your own sorting position to renderers (at least ParticleSystemRenderer and MeshRenderer) instead of using the bounds' center. That could help problems like shown here https://forum.unity.com/threads/sorting-fudge.450248/#post-3313121, or for sorting with a particlesystem in 2D, where I'm currently assigning the first 2 particles to be stationary and live forever at specified min/max depths that no other particles would spawn outside of, in order to force the bounds to have a specific center z value, so it won't randomly change ordering with sprites, but that is a very ugly and limiting workaround.
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    We have recently added the ability to set a custom bounding box for any Renderer, does that sound like it would help?
     
  3. PrecisionCats

    PrecisionCats

    Joined:
    Nov 19, 2017
    Posts:
    40
    Not really. It's possible to expand a bounds to have its center be in the location you want, but that means that culling would think it might be visible when it definitely isn't, defeating the purpose of culling.
    In the example I linked, I believe the sorting position should be around the emission location, which is far off from the center of the bounds, so it could basically quadruple the area culling thinks it's visible.

    Also, SpriteRenderer already gives some control of the sorting position (center or pivot), and if it's important enough for SpriteRenderer, it should be important for 3D where sorting is much more nontrivial.
    As it currently works, using the center of the bounds, rotation of the local positions in the mesh matters a lot, for example (sorry for how ugly this is):
    upload_2021-7-21_21-20-14.png

    The left and lower right could sort the same by finding the worldspace bounds, but if the world is rotated it would be inconsistent. It would depend on how you design your levels, the rotation of everything, not how it ends up looking like to the player.
     
    Last edited: Jul 21, 2021
    fleity and richardkettlewell like this.
  4. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    345
    I want to +1 this. Custom sorting point for mesh renderers would be highly appreciated.
    I have an isometric game with arbitrary shaped meshes as world objects and custom sorting pivots would enable me to automatically sort everything instead of relying on a huge amount of manual sorting and switching with layers and ids.
     
    richardkettlewell likes this.