- Home /
The CanvasRender.OnTransformChanged use CPU much
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...
OR:
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 · Apr 21, 2017 at 09:30 AM
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.