Hey if anybody could shed some light on this I'd be grateful... Basically I'm determining the render order of all my on-screen gameobjects each frame by setting their vertices each frame - and setting the z value to determine which should be down in front of which... The objects are all flat planes with just 4 verts .... This all works fine most of the time - but in some places where I'm sure that the z verts are being correctly assigned, some objects which should be in front of others are being drawn under them... And I really can't see why... FYI - this is a conversion from an iPhone game so that's why I'm doing it like this - in the original code the objects were rendered in the precise order they should be drAwn so each time I draw something I increase a global var that contains the z-depth for the next drawn object... Camera is orthographic... Any clues? Thanks, Ross
Not all shader perform a ZTest. Make sure yours do.
In Unity the forward direction is along the z-axis, so make sure you're not mistaken with it. The z coordinate and the z of the z-buffer are two different thing.
Answer by ScroodgeM
Aug 16, 2012 at 12:01 PM
first. check this
second. check shaders. shaders also have a render queue value that is more important that z position. shader with lower queue value will render first.
third. for transparent objects they are sorted using it's pivots. so be sure not vertices but pivots are sorted in right order
Answer by Triggly_Glix
Aug 25, 2012 at 04:26 PM
Thanks for your answers here - The problem did seem to have something to do with using the transparent shader - when i turned it off - everything was rendered right - the solution that finally worked for me was to set the 'render queue' value for each GameObject's mesh renderer material - like so...
so each frame for each GO it's ... ...
meshRenderer.material.renderQueue = Globals.renderQueueCounter; Globals.renderQueueCounter += 1; ...
methinks you should fix object's pivots. check any two objects that are renders in incorrect order - what is the distance from camera to that objects pivots?
i admit i didn't put too much effort into it but i couldn't really see where the pivots were - as the objects are all simple planes i presumed the pivot would just be in the middle of that plane. I'm repositioning them by changing the 4 verts - that doesn't also change the pivot?
it's an orthographic camera - my first attempt to get render order working was by using the z - axis... but that wasn't working...
repositioning verts always leave pivot in place, cause vert has coordinate relative to pivot. so you should use verts position so that one dimension is 0. for example (1,1,0) (-1,1,0) (-1,-1,0) (1,-1,0) and move along z axis using pivot (gameObject.transform.position)
I'm repositioning them by changing the 4 verts - that's an answer to your issue 8)
Hey thanks Scroodge - you are totally right - i fixed it as you recommended and it's working perfectly...
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
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.
Answers and Comments
10 People are following this question.
A bit more texture detail in Vertex Lit
Click and Drag Camera only works in Orthographic camera
Unculled particle system rendering
How do I lock the width on an orthographic camera?
camera setup for orthographics