Accessing the .rect property of a RectTransform is very expensive compared to other operations.
On an AMD Ryzen 3900 it costs:
Accessing RectTransform.rect 1000 times cost 2ms
Accessing RectTransform.localToWorldMatrix 1000 times cost 0.6ms
The RectTransform.rect property is used across a lot of Unity UI code. I believe the overall UI performance can be affected positively by optimizing RectTransform.rect.
Does not feel like it would hurt to open a bug ticket. Worst case it just gets closed. Best case a dev sees whether there is actually some low hanging fruit to improve.
It does kinda make sense - the rect property is calculated, while the other properties are just fields. It also (probably) needs to walk the hierarchy and deal with all the garbage that is layout groups and whatnot.
Did this get way worse in 2022?
I sincerely believe uGUI should never have been shipped. Itās just a very big bug that pretends like itās a feature.
Iāve had a quick look at the code and indeed itās not trivial - it walks the parent hierarchy looking for changes. There is nothing obvious to optimise just by reading it. If a bug report got past QA someone could profile it to get a better idea of the hotspots. The UI team may be focussing on UIToolkit these days though⦠sorry I dont have any good news about it.
uGUI has been basically abandoned since it was moved into a package to open room for UIToolkit. As per usual for anything Unity, development on the old feature stops long before the new one is ready.
Wow, very cool of you to have looked into it. Thank you!
I wish Unity would still improve a few things in old systems, because weāre still using most of them and will continue to use them even in a few years. Where āweā refers to the company I work. But I understand that you (plural) donāt want to break old systems by working on performance improvements for example.
Having the UI project repo available on GitHub would be epic, at least then we could submit PRs for improvements (like removing cases of transform.GetComponent())
I have to say that the regular Particle System is probably one of the most complete things in Unity. You canāt really make it do any more that doesnāt make sense being done elsewhere. Also a few other bits and bobs feel pretty done to meā¦
But IMHO UI was never done because one of the chief objectives of a built in UI would be really high performance as thatās kind of why you will use a UI vs just slapping a few quads/sprites/text on the screen. In that, I would say UI was never finished.
Doing a brand new UI Toolkit thing seems again something fairly separate from DOTS and Iāve already decided not to use it, based on past experience and the fact itās far from finished.
Rolling my own UI for my stuff, as I can guarantee the performance and its probably a hundred thousand times easier to use.
Haha I will never sell on asset stores or anything like that. What I mean is in my past games and my current even, I just normalise where the screen edges are and snap 3D objects there like TextMeshPro objects, or health bars, that sort of thing. Itās really no different to a game problem like a 2D game. I got the habit of UI like that from @MelvMay many years back when having fun with Torque2D.