Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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.

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

How would I fix this DrawMeshInstancedIndirect and Translucent object problem? 0 Answers

Skinned Mesh Renderer Rendering Order (Priority) Issues 0 Answers

Problem with rendering? 0 Answers

How do i change the Alphasorting Center to the Pivot in Meshrenderers? 0 Answers

Sprite rendering order on perspective camera 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges