Z order not working when moving texture

Hi

We have a simple sprite setup in Unity with transparent cloud plane object in front of a sky plane object. This displays perfectly until I move the UV texture of the clouds to make them move with the following line:

renderer.material.mainTextureOffset = Vector2(Time.time * 0.2);

The UV texture moves exactly as I want it but the cloud plane object displays behind the sea plane object. It’s as if as soon as i move the texture with the code above the Z-buffer gets confused and puts it at the back.

The cloud plane uses a Transparent/VertexLit shader - we’ve tried all the other Transparent shaders and they do the same. However, the CutOut shaders do work OK when the texture is moved but look damn ugly.

Also this behaviour only happens in Unity iPhone (hence why this is post is here) - I tested the project in Unity Pro and it works perfectly. This suggests it’s either a bug with Unity iPhone or it’s something that’s possibly not supported for the iPhone (although I can’t see a reason why if the shader works when not moved).

I can work around this problem by moving the objects instead but just thought i’d throw this one up in case anyone is aware of a solution.

Any ideas much appreciated.

Cheers
Paul

I’m not positive this has been fixed in the upcoming release (I will make sure to ask), but in the meantime you can fix this with the following line of code included in your scrolling script…

renderer.material.renderQueue = 0;

Let me know if this temp fix works,
Ethan

Thanks Ethan. It didn’t quite work exactly as you suggested but if i set all my transparent sprite object materials (there are a few levels) to…

renderer.material.renderQueue = -1;

…it then works perfectly… all objects are drawn in the order they are positioned in the scene.

Thanks again.

I’m not positive, but this sounds just like a problem I was having. I think this is going to be addressed in the up-coming hotfix.

upcoming hotfix? anyone have an ETA and what other updates it will likely include?

Sam and I formally filed this bug into the database again tonight just in case it had been overlooked (we ran into it making the Tunnel Runner example and thought it had been addressed).

The official ETA is “right around the corner” :wink: … it’s in RC2 testing phase right now.

Ethan