Search Unity

Graphics.DrawMeshInstancedIndirect and sprites draw order

Discussion in 'General Graphics' started by bitHussar, Dec 30, 2021.

  1. bitHussar

    bitHussar

    Joined:
    Jan 9, 2016
    Posts:
    33
    I'm working on a 2d side scroller game with large tile-based map. For the tile rendering I have made a custom script that renders the tiles using Graphics.DrawMeshInstancedIndirect and a custom shader. All other graphics for player, enemies, projectiles, etc... are rendered using simple SpriteRenderers.
    The map has 3 layers along the z axis: background (1), actual map (0), foreground (-1) and we use a perspective camera for the parallax effect.
    We would like the SpriteRenderers to be rendered between the actual map layer and the foreground, however I couldn't find a way to do it.
    Sorting layers for sprites is made for this very porpose but if I'm not mistaken they cannot be used with DrawMeshInstancedIndirect. Is there another way to do this or I'm going to have to replace all SpriteRenderers with custom rendering script and sort them manually?

    upload_2021-12-31_0-54-22.png