Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: SaladPlantation on May 14, 2013, 11:37:37 AM

Title: Adjusting Z Between Different Atlases
Post by: SaladPlantation on May 14, 2013, 11:37:37 AM
I know this is a common issue, and the questions come up all the time. I've read through a bunch of threads and found nothing wrong with my depth issue.

I have three atlases, and I know using depth only works with an orthographic camera with UISprites all on the same atlas. My question revolves around a weird glitch that came up on me. I have one set of images (atlas A, font) at -10, I have a second set of images (atlas B) at -5, and a third set of images (atlas C) at 0). They all share one UIPanel, and I confirmed that this UIPanel registers and reads these three atlases. This UIPanel also has no parent UIPanel, so it's fully in control. Now it's obvious I want atlas A on top, followed by atlas B, and then atlas C.

The problem is that atlas A is at the back. I've tried messing around with different things to get atlas A on top, and the only thing I've found that fixes it is (during run-time) checking off Depth pass. It doesn't matter whether or not depth pass is on or off to start, the draw order only gets fixed when it's checked off or on during run-time. Once you do this, checking it again does not reverse the process. I've tried many different hierarchy combinations to attempt to fix this but I cannot find a solution.

The images are a complex button that is built during run-time. The buttons use UISprite in combination with UILabel and all buttons are placed into a UIGrid. Each button has UIDragPanelContents on it and the UIPanel has UIDraggablePanel on it. Perhaps I've done something wrong here?

Is there some other solution other than checking off Depth Pass on the UIPanel? If more information is needed please let me know.
Title: Re: Adjusting Z Between Different Atlases
Post by: ArenMook on May 14, 2013, 12:12:22 PM
I see no reason why this would happen with the latest version of NGUI, so I suggest you select your panels and turn on Debug geometry, then select the draw calls to see what's actually being drawn. Switching to a perspective-based camera in the scene view here will give you a better idea of what's happening.
Title: Re: Adjusting Z Between Different Atlases
Post by: wizardsmoke on May 14, 2013, 12:15:29 PM
In similar situations, the thing that worked for me was separating each of these depth layers into separate panels that are each at different z positions.  I was using an earlier version of NGUI, though, so it may not work the same now.
Title: Re: Adjusting Z Between Different Atlases
Post by: SaladPlantation on May 15, 2013, 11:47:26 AM
In similar situations, the thing that worked for me was separating each of these depth layers into separate panels that are each at different z positions.  I was using an earlier version of NGUI, though, so it may not work the same now.

Unfortunately I'm pretty limited on my draw calls, developing for a mobile platform. This isn't really an option.
Title: Re: Adjusting Z Between Different Atlases
Post by: SaladPlantation on May 16, 2013, 12:39:07 PM
So after confirming that my NGUI and Unity are both up to date (Unity 3.5.7 is my Unity version) this problem still occurred. I started to mess about to try and fix this problem and discovered that the order at which you gameObject.active = true makes the z of the transforms irrelevant for the depth.

So while atlas A has a z of -10 and atlas C has a z of 0, if all objects in atlas C are gameObject.active = true before objects in atlas A, then atlas C images are on top of atlas A images.

To fix this I made a silly little coroutine that starts by turning everything in the button off. Then turning on atlas C, waiting another frame until turning on atlas B, then waiting another frame before turning on atlas A. This fixed the problem I was having.
Title: Re: Adjusting Z Between Different Atlases
Post by: Nicki on May 17, 2013, 03:26:58 AM
Almost exclusively this problem is caused by a single widget that happens not to be in the correct depth, so something from A could be at +10 or 0 instead by some accident.

In all cases, don't use Depth Pass. It's nearly always bad.
Title: Re: Adjusting Z Between Different Atlases
Post by: SaladPlantation on May 20, 2013, 09:21:21 AM
So it seems my little coroutine didn't work.

I've noticed something else that's odd in my scene. I can normally change the z on a gameObject that has a UILabel on it via the manipulator in the scene view, but with the UILabels that aren't layering correctly I can't. Would anyone know the reason for this? I have a feeling it could be what's causing the issue. I've tried changing the z transform via inspector but it doesn't ever change the location of the gameObject in the scene even though the number has changed and doesn't change back to what it was before (not being changed via script somewhere).
Title: Re: Adjusting Z Between Different Atlases
Post by: ArenMook on May 20, 2013, 09:35:00 AM
Is your panel marked as static?
Title: Re: Adjusting Z Between Different Atlases
Post by: SaladPlantation on May 20, 2013, 09:43:02 AM
No, panel isn't marked as static.
Title: Re: Adjusting Z Between Different Atlases
Post by: ArenMook on May 20, 2013, 09:56:36 AM
Then there is no reason why adjusting a game object wouldn't move it. Unless the object's child is anchored.
Title: Re: Adjusting Z Between Different Atlases
Post by: SaladPlantation on May 20, 2013, 10:16:23 AM
I can move x and y, but not z.

Right now I have an anchor, with a child that has tween position on it. From there I have the next child with UIPanel and UIDraggablePanel, a child of that is a UIGrid. Then all the children of the UIGrid are UIButtons, with children in there that are the labels. The UIButtons also have UIDragPanelContents on them. I'm not sure if this helps at all.

I can adjust the entire UIButton's z, but none of the children of it. Perhaps it's something to do with UIButton and it's box collider?
Title: Re: Adjusting Z Between Different Atlases
Post by: SaladPlantation on May 20, 2013, 11:34:34 AM
Finally solved the issue.

I couldn't locate the problem, but I rebuilt the entire UIButton structure (where the problem was coming from), with the exact same properties and I can now move the Z. It seems the prefab had somehow locked it's Z on me, although I'm not entirely sure how.
Title: Re: Adjusting Z Between Different Atlases
Post by: freeglass on June 08, 2013, 12:21:25 AM
NGUI Depth Manager you requested issues can be fixed by using.

This program is a tool designed to help solve problems that occur while using NGUI Widgets Depth .

NGUI Depth Manager in AssetStore (https://www.assetstore.unity3d.com/#/content/8722)
Title: Re: Adjusting Z Between Different Atlases
Post by: LaserCannon on August 26, 2013, 05:09:11 PM
So I had this problem, researched it, found this thread, but still couldn't get it to work.

But I think I found your problem. So for anyone coming to this thread via Google:

NGUI sometimes sets the scale of things to zero. It's kind of obnoxious, yes. But also--perhaps because of a Unity update--you can't MOVE things in a direction if one of its parent objects has a scale of zero in that direction.

So if I have the heirarchy:

-MyParent
--MyChild
---MyGrandChild

...and 'MyParent' has a z-scale of 0, then trying to move 'MyChild' or 'MyGrandChild' in the Z-direction is impossible.

It's an annoyingly easy thing to overlook.

I hope this helps!
Title: Re: Adjusting Z Between Different Atlases
Post by: ArenMook on August 27, 2013, 02:31:31 AM
NGUI should never set scale of anything to zero.
Title: Re: Adjusting Z Between Different Atlases
Post by: SaladPlantation on February 20, 2014, 05:35:49 PM
Finally solved the issue.

I couldn't locate the problem, but I rebuilt the entire UIButton structure (where the problem was coming from), with the exact same properties and I can now move the Z. It seems the prefab had somehow locked it's Z on me, although I'm not entirely sure how.

I have gone back to the same project and actually found that somewhere in the hierarchy the z was set to a scale of 0, preventing an transforms that were children from moving along the z and causing issues with separate atlases being unable to define which to draw on top of which. This wasn't in the same place I was having that issue but I assume this was the issue I ran into.
Just wanted to come back and post what I think was the solution.