Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

HDRP Material Sorting Priority C# Scripting

Discussion in 'High Definition Render Pipeline' started by Korindian, Jan 6, 2021.

  1. Korindian


    Jun 25, 2013
    What is the appropriate way to set HDRP Material Sorting Priority using C# scripts for transparent materials?

    This documentation page only explains setting the render priority of Mesh Renderers via scripting.

    After a simple scripting test, here's what I've discovered:

    Using the following code:

    Code (CSharp):
    1. material.SetFloat("_TransparentSortPriority", 1);
    will set only that property, but will not change the actual sorting.

    After using that code, if I select a different GameObject, and then the one with the material on it, or If I change the inspector window's mode to "Debug" and then back to "Normal", the material will "refresh", and the renderQueue will also be set to 3001, and the actual sorting will update.

    If I use the following code instead:

    Code (CSharp):
    1. material.renderQueue = 3001;
    renderQueue updates and the actual sorting does get changed.

    However, the _TransparentSortPriority doesn't update, so if I select another GameObject and then select the one with the material on it, or if I change the inspector window's debug mode and back (causing the material to "refresh"), the actual sorting AND renderQueue reverts back to the original state, because _TransparentSortPriority never changed.

    Obviously both of these are not ideal, so I'm using the following:

    Code (CSharp):
    1. public Material material;
    2. public int sortingPriority;
    4. [ContextMenu("ApplySortingPriority")]
    5. private void ChangeSortingPriority()
    6. {
    7.     material.renderQueue = 3000 + sortingPriority;
    8.     material.SetFloat("_TransparentSortPriority", sortingPriority);
    9. }
    This seems to handle the problems of using either individually, but surely this is not what the HDRP devs intended? Will this stay the same, or will this change in future versions of HDRP?
    Armegalo likes this.
  2. Armegalo


    May 14, 2018
    Same question!
  3. doctorclue1024


    Jul 25, 2021
    I thinnk hdrp dosen't support render priority in 3d.
    use transparent mat = backfacecull / zdepth = priority doesn't work
    It's been a few years since the HDRP was released, and at this point, they don't seem to have the ability to correct the problem.
  4. UrbanNuke


    Jun 11, 2019
    Any solutions?
  5. Homicide


    Oct 11, 2012
    Im having a beech of a time trying to get my car to render always on top of terrain details, instead of grass always coming in the car interior. Additionally, i cant seem to get my rain to stop falling 'inside' the car either. Im at the art / polish stage of my little game, and this is killing me.

    I read over the HDRP material sorting and renderer sorting, but it seems incomplete, and not all encompassing, and i cant make any sense of custom passes, so im at a loss here.

    This was really easy to accomplish in the standard rp, and probably is in HDRP too, if you know how. If anyone knows of a video, or guide, document on the subject aside from the Unity Docs, as that just isnt working out for me.