- Home /
How do i change the Render Queue ?
I was having problems whith the rendering order of two transparent materials and i was advised to set the render queue of the object in question (a spaceship shield) to Transparent+1, since they are both probably currently set to Transparent. HOW DO I MAKE THIS MODIFICATION ???
(apparently it has to do with the Unity ShaderLab, and i dont know anything about it).
Here is the inicial question: http://answers.unity3d.com/questions/996834/how-do-i-correct-the-rendering-order-of-two-transp.html
Answer by CHPedersen · Jul 22, 2015 at 06:11 AM
You can do it with shaders by changing the Queue tag in the subshader tags list, indeed. See link posted by getyour411 for the documentation on that.
But there's an easier way, if you're not comfortable working with shader code. It's possible to override the render queue number from scripts instead. Use Material.renderQueue, for example like this:
renderer.material.renderQueue = 3001;
Notice that 3001 is the same as "Transparent+1" in a shader, because the string "Transparent" in shaderlab is actually just a placeholder for the number 3000. All transparent objects have renderQueue numbers equal to or greater than 3000.
If you don't set the render queue value in script, It's worth noting that if you set the it in the shader after creating a material, the existing value in materials using the shader will not be updated unless you edit them in a text editor or in the debug inspector, since it's not a parameter that is exposed via the UI normally.
https://docs.unity3d.com/ScriptReference/$$anonymous$$aterial-renderQueue.html "Note that once render queue is set on the material, it stays at that value, even if shader is later changed to be different."
If you set the render queue to -1 in the debug inspector, it will always use the queue specified in the shader, not the "cached" queue from when the material was created.
Awesome! For us non engineers, can you provide the script? Thank you.
Answer by Acreates · May 25, 2017 at 07:11 AM
Awesome! For us non engineers, can you provide the script? Thank you.
Answer by felix_of_mars · Jul 16, 2017 at 02:41 PM
This doesn't work, as soon as you enter the play mode it resets back to Transparent as the default.
Thats because you write the code in the Start method, if you write it in the Update method, Unity will adjust the renderQueue to the value that you wrote every frame . You can also write:
[ExecuteInEdit$$anonymous$$ode]
If you write it over the script name line, Unity will execute the code in the editor, and you will see that the renderQueue changes in the editor too.
I forget why I needed that, but writing it in the update seems not very optimal.
In a game that has very high graphics and an advanced AI it will not be optimal, but in a simple game that don't requires a lot, it will not make problems
Answer by Fattie · Aug 02, 2020 at 10:44 PM
I found that you CAN actually just set the custom render queue in the editor,
but it's simply flakey.
In current Unity, you sort of have to set it and then quickly press Play (regardless of what scene you're in or whatever), and then it does seem to "stick" from there on.
Just another Unity hassle! Hope it helps someone.
Your answer
![](https://koobas.hobune.stream/wayback/20220611232406im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Standard Shader Still Visible through Stencil Shader 0 Answers
ARCore – not changing alpha on material after changing BlendMode through code. 1 Answer
Why does the 3D Text shader show specular at certain angles? 2 Answers
Order dependent transparency, shaders (planet atmosphere rendering) 2 Answers
Two transparent objects passing through each other problem 1 Answer