• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by Julien-Lynge · Sep 27, 2011 at 05:09 AM · renderingorderrenderqueue

Setting renderQueue doesn't appear to change draw order

This seems like such a simple thing, judging by the Unity script reference and examples here, but I can't get render queues (set in the material) to work at all. I've set up a very simple scene with two boxes and a camera, one box behind the other (see picture).

Render test screenshot

Then, I added a script that changes the render queue of the two materials, flipping the queue order. I do a debug afterwards which verifies that the renderQueue value has been changed. The only problem is that the draw order doesn't change - the nearer cube is always rendered over the far cube.

I've included my code below. As you can see from the comments, I tried setting the renderQueue in the renderer.material, sharedMaterial, and the material asset directly, and in all cases the renderQueue value changes but the render order does not. What am I missing here?

 using UnityEngine;
 using System.Collections;

 public class ChangeMaterialQueueOrder : MonoBehaviour {
 
 public GameObject go1;
 public GameObject go2;
 
 public Material m1;
 public Material m2;
 
 // Update is called once per frame
 void Update () {
     if (Input.GetKeyDown(KeyCode.F))
     {
         Debug.Log("Changing 1 to back");
         //go1.renderer.sharedMaterial.renderQueue = 1001;
         //go2.renderer.sharedMaterial.renderQueue = 1002;
         //go1.renderer.material.renderQueue = 1001;
         //go2.renderer.material.renderQueue = 1002;
         m1.renderQueue = 1001;
         m2.renderQueue = 1002;
         //Debug.Log("Render queue changed; go1 renderqueue now " + go1.renderer.material.renderQueue);
         Debug.Log("Render queue changed; m1 renderqueue now " + m1.renderQueue);
     }
     if (Input.GetKeyDown(KeyCode.G))
     {
         Debug.Log("Changing 1 to front");
         //go1.renderer.sharedMaterial.renderQueue = 1002;
         //go2.renderer.sharedMaterial.renderQueue = 1001;
         //go1.renderer.material.renderQueue = 1002;
         //go2.renderer.material.renderQueue = 1001;
         m1.renderQueue = 1002;
         m2.renderQueue = 1001;
         //Debug.Log("Render queue changed; go1 renderqueue now " + go1.renderer.material.renderQueue);
         Debug.Log("Render queue changed; m1 renderqueue now " + m1.renderQueue);
     }
 }
 }


P.S.: I'm using Unity Pro.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by Julien-Lynge · Nov 21, 2011 at 06:26 PM

Figured this out a while back. Render queue doesn't actually change what items are drawn on top of others, it simply changes in what order they're rendered (so something needed for a reflection, for instance, can be rendered before the thing that needs to reflect it).

The depth buffer (or z-buffer) is what determines what is drawn on top of what, or more correctly how far from the camera things are drawn. This video and the following couple of clips do a great job of describing how the depth buffer works and how to change draw distance for objects:

http://www.burgzergarcade.com/tutorials/game-engines/unity3d/unity-ios-shaderlab-tutorial-10-1-z-fighting

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image deliriumz · Dec 06, 2012 at 11:09 AM 0
Share

Thank you very much, this saved me quite some hassle :)!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Set RenderQueue for Terrain 2 Answers

HDRP DepthMask Possible? 0 Answers

Understanding Render Targets and Render Textures. 1 Answer

Unity2D sprites overlapping 2 Answers

Standard Shader Still Visible through Stencil Shader 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges