Extreme optimization of UGUI

There are always endless topics about UGUI optimization in unity. There are many optimization methods. The one I want to talk about today is a simple optimization. In fact, developers feel that there is no optimization method to adopt.
First of all, when you create a UI component, the UI component will automatically turn on "Raycast Target". In fact, when the UI does not need to interact, this function can be turned off. If you turn this off, It is also a big performance optimization method.

insert image description here

Raycast Target.png
The second type, try not to check the "Best Fit" option for the text component, because when you check this option, unity will do a lot of calculations in the background, and put all the font sizes that meet the regulations one by one After traversal, if this option is checked, it not only consumes resources but also occupies memory.

insert image description here

Best Fit.png
The third type is the batching of UI. What is the batching of UI, that is, if two consecutive components under the canvas (including parent-child relationship) are the same type of components, then unity will treat the two UIs as the same component when calculating, and draw once. The proof is as follows:
add a button component and a picture component to the scene, and the number of drallcalls at this time is: 5
insert image description here

Add description
Added a button and a picture scene.png
Now, I add multiple images under the Image, and add multiple text components under the child of the button, and then look at the number of drallcalls
insert image description here

Added multiple images and text
At this time, due to the batching of ui, the drallcall has not changed.
So what happens if they are not adjacent but interspersed?
insert image description here

Renderings
will not be batched. What is the reason for not doing the batching? Because they cover each other, what happens if they are set not to cover each other?
UI without overlay
insert image description here

Then unity will still batch it.
Although there are very few drallcalls in batches, in many pages, and if your project is running on a platform like a mobile phone, then such extreme optimization is necessary.

Guess you like

Origin blog.csdn.net/weixin_41590778/article/details/129400175