Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: breakmachine on October 10, 2013, 02:00:33 AM
-
I have these healthbars consisting of a panel with two sprites underneath ("a" & "b"). When spawning the healthbars they all get the same panel depth. This means that sprite "a" shares the same depth as all other sprite "a". And for some reason this results in two drawcalls per panel.
Do I have to manage the depth of the spawned panels to prevent this and if so are there any shortcuts such as finding next available depth?
-
The panel will split up its draw calls if there is another panel with the same depth that has widgets sharing the depths with the original panel, but not the materials. Easiest way to fix it is to ensure that your instantiated health bars are sitting on a panel that has a depth that only matches other health bars.
-
But if I have one panel per healthbar (since they are "ever moving" and I need to reduce GC )that means I have to manage the depth of all those panels so they aren't the same. Would be handy to have some function to get next available depth or something.
-
Have one HealthBar parent, which has a panel that holds all health bars (and nothing else). Since they all move all the time anyway, there's little gained by having them in each of their own panel.
-
@Nicki
Hi Nicki. I'm having trouble keeping down memory allocation on the heap in my game so I don't want new mesh to be generated every frame. Therefore, by making one panel per healthbar and moving that healthbar instead of the sprite I can make them static.
-
Ah ok, I see your issue then.
You'll likely have to make a little system that handles depths for those panels - so you have a pool of ints that you can use, and keep track of which are being used and hold it like that in a sort of depth pool.
Alternatively, you do the same thing for each individual widget inside the health bar, but that can quickly become complicated.
For this particular issue, the old way NGUI did it would have been easier.
Maybe each panel should have some sort of "isolate draw call" bool, so its draw calls can be its own?
-
Each panel generates its own draw calls. Extra panels can separate draw calls further, but they will never merge draw calls. For example you will never have widgets from panel A end up in the same draw call as widgets in panel B.
So to that extent, all panel draw calls are already isolated. Having health bar panels have the same depth as each other is not an issue here. Panels moving will only affect their own draw calls.
-
Thank you for your quick replies!
Since I'm pooling my healthbars I just added a counter that gives them unique depths. But I'm still getting GC Alloc. Could it be that I have filled sprite in my static panel? Woud changing fillAmount cause a redraw?
-
Of course it does. Any and all changes to sprites cause the draw buffer to get re-generated.
-
And I guess an anchor that isn't set to run once will do the same :)
-
I'm almost there...
When setting the depth of my spawned healthbars the setter function sets all drawcalls to isDirty and mFullRebuild to true. That includes the drawcall from my static panel. Which of course results in a large allocation.
I'm thinking of doing and extension with a function to set depth without marking everything as dirty but maybe there's a better way?
-
Problem with that is changing depth has potential to alter the draw calls themselves as it changes the draw order and alters how widgets get broken up into draw calls. This is why a full rebuild is needed. Can it be optimized? Certainly. But I haven't done any clever hacks on this yet.