Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: c-Row on May 04, 2013, 10:34:15 AM
-
Is there a performance difference in where you put your anchors in NGUI? If I want to labels, one in the top left and the other in the top right corner, should I add them to the same panel and add an anchor to each of them, or should I create a panelTopLeft and a panelTopRight, each with an anchor on its own? Or does it come down to personal preference?
-
Anchor a panel, make labels a child of that panel. Moving a panel is always faster than moving widgets, and the fewer anchors you have, the better the performance will be.
-
The Unity profiler may be throwing you some red herrings if you're looking to optimize here, since the actual UIAnchor.Update isn't necessarily heavy if you anchor individual elements in a UIPanel, but UIPanel.LateUpdate will be very heavy, because the moving of widgets inside a UIPanel has the sideeffect of making the panel redraw everything it is responsible for drawing.
Put anchors as high as you can in your hierarchy and do your best to have UIPanels below them, so any given UIpanel doesn't need to be rebuilt every update.
-
Looking at the UIAnchor class, it looks like the anchored object is repositioned every frame - is this necessary?
I have a mobile app and generally I am anchoring widgets to sides of the main window, and since my orientation is locked to landscape the main window never changes size. If repositioning only occurred in the Start() function, would this combat the performance issue you mentioned above (relating to anchoring widgets rather than panels)?
Thanks!
-
Oops I just saw the line at the end of UIAnchor that says the transform is not applied if it isn't changed! It's still recalculated but I suppose the overhead of this is relatively small.
-
I'm considering making a option in the anchor so it can "one shot" the anchoring and then turn itself off. We tend to have to have something else turn the anchor off, if we want to animate things and such so it could be useful. Plus, for all mobiles, the resolution never changes, so it wouldn't hurt to only have the overhead once.