Search Unity

Can we force GPU instancing on 2D Sprite Renderers that have different sorting order?

Discussion in 'General Graphics' started by Phan-Phantz, May 20, 2019.

  1. Phan-Phantz


    Nov 11, 2015
    In my 2D project, I use GPU instancing to batch the draw call of SpriteRenderers that shared the same texture and material. But, it turns out that if the renderers have different sorting order the batching doesn't work. Can we somehow force GPU instancing on 2D SpriteRenderers that have different sorting order? As it said in the Unity manual that you can use Graphic.DrawMeshInstanced() to force Unity to use GPU instancing on objects that have different sorting order, I can't find any example to do it on sprite renderer.

    My situation :
    I want to create a crowd of 2D NPC in the scene. Each of them has 16 body parts such as arm, leg, body, etc. The parts have been sorted by different sorting order on the same sorting layer. So, when 2 NPCs walk pass each other I use Sorting Group and custom axis to make the NPC who has lower y position appear in front of the one who has higher y position. The problem was that Sorting Group breaks batching.

    PS. I'm working with 2018.2 version and without ECS.
    Last edited: May 20, 2019