Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: DoctorWhy on August 10, 2012, 01:59:59 PM

Title: Strange depth drawing bug
Post by: DoctorWhy on August 10, 2012, 01:59:59 PM
This is a really strange bug, and my system is kind of big now, but I will try and do my best to describe my problem.

I have 2 GameObjects that are windows, each have their own parents, and their parents are parented to the same object:.  These 2 GameObjects are ViewWindow and AdjustWindow.  Each window has a bunch of children (which are NGUI objects, such as sliders and buttons).  So, the structure is

RightMenu
has View and Adjust.
View has ViewWindow and Adjust has AdjustWindow.
Each Window has several NGUI children.

ViewWindow has 3 sliders and a bunch of buttons.  AdjustWindow has a bunch of sliders, and 3 buttons.  Each window has a background UISprite as well.  Both backgrounds are on the same Z, and have the same depth of 0.

Whenever ViewWindow and AdjustWindow are both open (active in Unity), the 3 AdjustWindow buttons look like they go behind the AdjustWindow background, though nothing on them changes what so ever, and they are in the same location in the Unity level view thing.  I noticed that if I move the AdjustWindow's background behind the ViewWindow's background (higher Z value), the AdjustWindow's buttons come forward, but the ViewWindows sliders now are doing the same thing the buttons were (but the buttons on the ViewWindow, and Sliders on the AdjustWindow are unaffected).

I don't know if I explained my problem well enough (if you need more details, ask), but this is a very strange problem, and I can't seem to get it so everything is drawn how I want it to be.

EDIT:
I tried to make the depth of the background -1000, and the depth of the buttons +1000 on the AdjustWindow, but that doesn't seem to do anything at all.

ANOTHER EDIT:
It looks like whenever I move one UISprite to different Z position values, whichever window has a UISprite with the furthest Z  value will show all of their sprites correctly.  But both windows cannot show everything correctly; one is always screwed up.

And apparently, if the Window itself, or the parents are moved, it doesn't have an affect.  But if I move the children of either window, whoever has the furthest away local position will show correctly.

ANOTHER:

Screenshots to help explain the problem.

Adjust.png - Just the adjust menu is active
AdjustAndView1.png - Both are active, but reset button looks like it is behind
AdjustAndView2.png - I move the reset button forward, right when it comes in front, the view sliders go behind.
Title: Re: Strange depth drawing bug
Post by: ArenMook on August 10, 2012, 04:36:05 PM
1. Use only one atlas. Make sure your font is in your atlas.
2. Each window should have its own panel.
3. Don't adjust Z on widgets. Adjust Z on the panels.
Title: Re: Strange depth drawing bug
Post by: DoctorWhy on August 10, 2012, 05:11:48 PM
Thanks for the reply.  A couple questions to clear things up for me.

Use a single atlas for every image related to those windows?  A lot of images, but if it is, in fact, more efficient, that would make sense to do.

Panels can contain panels, correct?
Title: Re: Strange depth drawing bug
Post by: ArenMook on August 10, 2012, 06:19:05 PM
Each panel results in a new set of draw calls, even nested ones. A single atlas containing all the sprites you need will always be far more efficient than a bunch of different atlases. Think of it like this: every window is a self-contained element, so it needs a UIPanel to make sure that everything inside gets bundled into one object.