Author Topic: Does the depth reset itself when you create a new panel?  (Read 3261 times)

Bernard Parsons

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Does the depth reset itself when you create a new panel?
« on: March 07, 2014, 03:36:47 PM »
I've been working with NGUI for a short time, but I seem to have to just of it. Right now I'm trying to reduce the number of draw calls within my project, and I have to tell you that the UI I'm creating is very complicated and huge, so having as few draw call as possible is a must.

I know that keeping panels with their own depth number is a must or they with increase the draw calls, but does this apply to the widgets that are the child of the panel.

Example: I have a UI that contains several panels and each has its own level of widgets that contains sprites etc. Now I know that keeping the panels depth different like depth 0, depth 1, depth 3, so on and so on. But what about the assets I create under those panels, can each child under each panel be reset to depth 0 or will this increase the draw calls of each child that share the same depth?

Just to give an idea of whats happening, when my project isn't running I get about 54 draw calls and I still have allot more to do. Mind you I was getting over 245 draw calls before, but I have been going through everything and I'm slowly reducing it. And when I'm in run time I get about 21 draw calls, is it possible to get something so large and dependent on the NGUI feature that I should expect this to happen or is it possible to actually get everything down to 1 draw call?

If anyone has the answer it would be very much appreciated.

BTW, this tool is a god sent for a UI designer like myself. frigging genius for creating such a great add on to Unity. Thanks so much!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Does the depth reset itself when you create a new panel?
« Reply #1 on: March 08, 2014, 12:23:43 PM »
All panels batch their own child widgets. If you have nested panels, the child panel will "own" its child widgets, and the parent panel will only own widgets not already owned by the child panel.

Giving a unique depth is what makes it possible to change the draw order of panels (same as widgets). Panel depth supersedes widget depth -- all widgets are first sorted by panel depth (think: directories), and only then by widget depth (think: files).

To reduce draw calls, examine what draw calls you have by selecting the panel and clicking the View Draw Calls button. It will give you an overview of what's there, with the ability to see how many widgets result in each draw call. The best way to reduce draw calls is to avoid sandwiching different materials. For example if you have this kind of a structure:

Button Background (sprite, depth 0)
- Button Text (dynamic font label, depth 1)
-- Button Highlight (sprite, depth 2)

...then you are creating 3 draw calls, as first the background must be drawn, then the dynamic text, then the highlight. Re-organizing it so that it's like this:

Button Background (sprite, depth 0)
- Button Text (dynamic font label, depth 2)
-- Button Highlight (sprite, depth 1)

...will reduce draw calls, as now button's background and highlight can be drawn using the same draw call.

Reducing the UI down to 1 draw call is only possible if you use only 1 panel and one atlas, with no dynamic fonts.

Bernard Parsons

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Does the depth reset itself when you create a new panel?
« Reply #2 on: March 10, 2014, 07:46:54 AM »
Thanks for the feedback.
It seems I was doing everything correctly, it was the dynamic font that was causing the huge draw call issue. So now it's just a matter of converting them to Bitmap and I'm all good.

Cheers!