i only use localPosition in UGUI,without using scale etc.but in profiler, CPU Usage is high,this is picture. This problem has troubled me a long time. Help me~!
I have the same problem: I would assume UGUI would suspend recttransform's OnTransformChanged property while a gameobject is INACTIVE - however this is not the case:
Disabled gameobjects still fire the event on disabled rectTransforms, causeing huge CPU spikes when generating procedurally generated UI content (EG: list boxes of list items generated from prefabs - each instantiated item gets it's OnTransformChanged event fired while being layed out via code, even if the gameobject is not active).
I have a custom inputmananger in my project with editable axis, whenever I load my control input bindings screen on my settings scene - I get CPU spike whenever the UI is generated procedurally - mainly because OnTransformChanged is being called EVERY time i update a single recttransform property on instantiated prefabs (thus 3 times for setting scale) PER transform + all nested recttransforms.
Unity needs to stop processing ALL layout events for disabled objects in a scene...
We need something similar to the kind of SuspendLayout()/ResumeLayout() methods seen in WinForms whichs prevents scale/move,resize events from being fired during the time a procedural UI is being generated.
EG: (conceptual, please do this unity):
Canvas.SuspendLayout(); // layout the couple of hundred UI elements that are procedurally generated, // OnTransformChangedEvent should be completly suppressed // SetActive(True); on all procedurally generated child items (without triggering transform events) Canvar.ResumeLayout(); // Upon ResumeLayout should only run a single pass on all modified transforms/UGUI elements.
This would help solve many CPU bottlenecks currently caused bu UGUI during layout phases at run time.
Answer by akuno
Just solved it for my project: Do not move your canvas.
Had my Canvas as a child of the Player object, which was moving, thus trigged that event. Put your Canvas on a separate gameObject that doesnt move, and it shall be fixed.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
5 People are following this question.
Any way to use multiple font styles within a single UI Text component?
How to make a toggle not be deselected within a toggle group?
Unity 5 canvas animation laggs, why?
How to make advanced HUD elements using new UI components?
Playing Cards With Special Shrinking & Twisting Effects