How to permanently set the renderQueue variable for a material?

Hello!

Is there a way to set the render queue integer of a material (Geometry, Transparent, Overlay, etc), so that it stays this way after I hit stop again?

I want to stop using the shader's render queue for every tiny bit of geometry that needs to render before or after something. So I've tried this script:

void Start () {
  renderer.material.renderQueue = 1234; // some render queue integer
}

or

void Start () {
  renderer.sharedMaterial.renderQueue = 1234; // some render queue integer
}

which works great but (not surprisingly) resets every time I stop the playback. Is there a way to modify the material itself so that I could re-use it in other scenes as well, without having to use the script all the time?

Thank you!

Not that I know of. The only way I think you can do this is to copy the shader over and over again, using a different hardcoded Queue tag for each one.

(And for me, the value persists after I get out of Play mode, but is not persistent if I quit Unity and then reopen it.)

Yes, there is a way. I just discovered it due to a Unity bug… -.-

In Unity5, Unity introduced the “Standard” shader. Accompanying that shader is the “StandardShaderGUI.cs” Editor script, which does (amongst other things) exactly what you want.

In fact, it does it so perfectly well, that you can permanently change your Material’s render queue, and never be able to reset it, no matter which shader you are assigning… -.-

As proof, reproduce the Unity bug I mentioned:

  • Set the Standard shader’s RenderingMode of any Material in the Inspector to any value other than “Opaque”, for example to “Cutout”.
  • Switch the inspector to “Debug” mode. Notice the value “Custom Render Queue” being 2450 (=the internal default queue for cutout shaders).
  • Switch back to “Normal” mode. Assign ANY shader that is not a “Standard” shader to your material.
  • Switch back to “Debug” mode. Notice the value is STILL 2450, and if you create a test scene you will notice this really is the queue value your shader uses now.
  • The only way to RESET this hidden m_CustomRenderQueue material property is to once again assign the “Standard” shader, and switch that back to “Opaque”. This will set m_CustomRenderQueue to -1, which means the vlaue is ignored, and the actual queue value defined in the shader is used again.

=> So you should be able to somehow modify Unity’s “StandardShaderGUI.cs” script to just set your custom shader queue value - keeping in mind that this value will permanently ovveride all subsequent shader changes to that material, unless you reset it to -1.

Hi, i have meet such same problem when changed render queue of my material by changing render mode. But it revert any change of render queue every time i’have loaded my material, this because most Unity’s Shader Labs defines Tags in SubShader which controll render queue of this material paticlurari. When you load youre material no matter how befour you changed render queue it woud be redefined by “Queue” tag. But thanks for @Wolfram i’ve see in “StandardShaderGUI.cs” source that they using ValidateMaterial method to set property such render queue when you load youre material. So you just need create property in youre material and save there youre queue, then by using ValidateMaterial method and this property redefine renderQueue of youre material.