Author Topic: Depth value use  (Read 6428 times)

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Depth value use
« on: January 18, 2014, 02:41:33 AM »

I was under the impression that 'Depth' values is all thats required to control draw order between a hierarchy of UIWidget, UITextures and UISprites.

But I ran into a situation where I have a root UIWidget (depth: 0), a child UITexture (depth: -1) as a background image, a child UITexture (depth: 10) as a foreground image, a child UIWidget (depth: 5) w/ children UISprites (depth: 5) buttons, and a UIScrollView/UIPanel (depth: 1) w/ UIWidget + UITexture (depth: 1) elements under it.

And the draw order isn't as I expected (buttons and foreground are behind the UIScrollView elements). I was able to resolve the issue by adjusting the Z values, but is there a more proper way to setup the Depth values?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Depth value use
« Reply #1 on: January 18, 2014, 02:45:25 AM »
If panels are set to "Automatic" Render Queue mode, it's all based on depth. First panel depth, then widget depth. Otherwise Z does matter.

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Depth value use
« Reply #2 on: January 18, 2014, 02:56:22 AM »
What do you mean by "First Panel Depth", all panels in the hierarchy are drawn first then all widgets? or panel first then children widgets?

Presently in 'Automatic', I have a UIPanel with child UITexture at depth 1 thats being drawn on top of other UIWidgets at depth 10.

« Last Edit: January 18, 2014, 03:04:28 AM by ngui »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Depth value use
« Reply #3 on: January 18, 2014, 09:49:16 PM »
All widgets under the panel with depth of "0" are going to be drawn before all widgets under panel with depth of "1". Higher depth widgets are on top. Higher depth panels are also on top. All widgets are sorted by panel depth first, and only then by their own depth.

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Depth value use
« Reply #4 on: January 19, 2014, 11:16:24 PM »
Ok, so if i understand it correctly that still doesn't explain why the UISprite below is appearing under the UITexture below (numbers in the parenthesis is depth)

UIWidget (0)
   |
   |_ UIWidget (5)
   |      |_UISprite (5)
   |
   |__UIScrollView/UIPanel (1)
           |_UIWidget (0)
                 |_UIWidget (1)
                       |_UITexture (0)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Depth value use
« Reply #5 on: January 19, 2014, 11:20:53 PM »
Depth is not cumulative.

Also, you should never give the same depth values to different widgets. If you're cloning items that don't overlap, it's fine. But aside from that, make sure that the depth values differ. In your case both UIWidget and UITexture share the depth of 0. UIWidget and UISprite also share a depth of 5. It's confusing.

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Depth value use
« Reply #6 on: January 21, 2014, 01:49:17 AM »
I'll keep that all in mind and continue to have a play at it, thank you.

TeNDoLLA

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Depth value use
« Reply #7 on: March 17, 2014, 05:59:41 AM »
Having similar issues lately after I upgraded NGUI to version 3.5.1 but in this case with UISprite also. This is what I have

1. Panel that holds some widgets and all widgets has depth under 30.
2. Under the same panel one big UISprite filling whole screen that is kind of alpha curtain that gives a gray look to all the widgets described at phase 1. this particular UISprite has depth of 50.
3. Then again I have a bunch of widgets including buttons over the top of the "UISprite depth 50" and these widgets have depth of 60 and over. These widgets look like they are in top of the UISprite descriped in the phase 2, because they dont get grayed. but Camera DEBUG tells me all events goes to this UISprite that has depth of 50 which has lower depth than my buttons on top of it. That makes it impossible to use the buttons in this scenario. So what is going on?


Few days ago had another scenario also but otherway around, had one big UITexture which had depth of 50 and some widgets that had less than 50 depth. Still all these widget appeared on top of this UITexture. Am I doing something wrong or is there something fishy going on?

Edit:
Everything has z value 0.

Phase 1. Widgets are active from the start. Then from button press I activate the phase 2 and 3 widgets (is a pop up). Tried also to call panel.Refresh() after the activation which I do by calling NGUITools.SetActive, but did not help.


Edit 2:
Checked the drawcalls also and that alpha curtain sprite is drawn in DC 15 and the button sprites are drawn in DC's 17 and 19. Both buttons have box colliders also in correct place and size. But just somehow the events goes to the Alpha curtain which has lower depth.
« Last Edit: March 17, 2014, 07:35:47 AM by TeNDoLLA »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Depth value use
« Reply #8 on: March 17, 2014, 11:52:24 AM »
Events are depth-based if the UICamera is set to "UI" mode. If you set it to "World" mode, then events will be Z-based, not depth-based.

TeNDoLLA

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Depth value use
« Reply #9 on: March 18, 2014, 07:10:36 AM »
Thanks for the reply. The UICamera's Event Type is UI. Fixed the issue making the buttons from the scratch again. Still don't know what was going on but it works now. What I am thinking is the buttons were bugging or something and somehow the events went through them hitting the alpha curtain behind or something.