- Home /
How do I specify the render order of GameObjects?
I want to create a series of layers from my 3D objects. They all exist on a 2D plane, and can pass through one another. Rather than having them blend together when they collide, I want to render them in a controllable order, clearing the depth buffer each time, so that they are drawn directly on top of on another.
One way of doing this is to have multiple cameras that clear their depth buffers, and have specific culling masks. This works, but I find that as I add more cameras, frame rate takes a hit. Not only that, but it's a bit prohibiting, since I expect to have a large number of objects to draw in this ordered fashion. Further, the order in which they are rendered changes, which would make things challenging to juggle the culling masks and cameras as objects come in and out of play.
Any ideas of implementing this in Unity? Oh, and I don't have Unity Pro, so I need something that will work in the free version.
Answer by Eric5h5 · Feb 16, 2010 at 05:57 AM
You can use different shaders that specify a different render order but are otherwise the same. For example, one could have
Tags {"Queue"="Transparent"}
and another could have
Tags {"Queue"="Transparent+1"}
which would render on top of the first one.
Or you can use objects at different depths, and position the colliders so they all still collide with each other. There's no rule saying the collider has to be in the same position as the mesh.
Excellent, that works. I was looking at the shader queue tag, but didn't know that I could do something like +1.
Queue tag method works great, thanks all! Note that the Tags specification goes inside the SubShader (not Shader or Pass), as described here: http://unity3d.com/support/documentation/Components/SL-SubshaderTags.html
Note that you can also set material.renderQueue if you prefer not to modify the shaders, or you want to use the same shader in multiple queues.
Hi,
yes, it is work when the planes are the same scale and size however, I am going to put different size of plane just like wall and paper but it still keep twinkle... how can I fix it ?
Calvin
Answer by Jaap Kreijkamp · Feb 16, 2010 at 05:39 AM
Use an orthographic camera (checkbox in camera properties) and place objects at different depths.
$$anonymous$$y scenario already involves an orthogonal view. However, I want to use colliders/triggers, which will require keeping everything on the same plane.
your collider could extend into the z-plane as well! Your alternative is having every object a separate shader, then you can set the queue depth, or draw object yourself with Graphics.Draw$$anonymous$$eshNow.