Avoid UGUI Layout Groups (Vertical, Horzontal and so on..)

vvhustle's coding note·2022년 11월 22일
0

Layout Group은 비효율적으로 업데이트 됩니다. (root canvas부터)

콘텐츠가 동적이지 않은 경우 Layout Group을 사용하지 말고, 비율 레이아웃에 앵커를 대신 사용하는 게 낫다고 합니다.

그 밖의 경우라면 동적 UI 설정 후에 커스텀 코드로 Group.enable을 꺼서 컴퍼넌트를 비활성화 시킵니다.

중첩 Group은 더 더욱 성능을 떨어트리므로 지양해야합니다.

(적어도 투뎁스로 사용하지는 말자)

Avoid layout groups when possible
Problem: Every UI Element that tries to dirty its layout will perform at least one GetComponent call.

When one or more child UI Element(s) change on a layout system, the layout becomes “dirty.” The changed child Element(s) invalidate the layout system that owns it.

A layout system is a set of contiguous layout groups directly above a layout element. A layout element is not just the Layout Element component (UI images, texts, and Scroll Rects), it also comprises layout elements – just as Scroll Rects are also layout groups.

Now, regarding the problem at hand: Every UI Element that marks its layout as “dirty” will perform, at minimum, one GetComponent call. This call looks for a valid layout group on the layout element’s parent. If it finds one, it continues walking up the Transform hierarchy until it stops seeking layout groups or reaches the hierarchy root; whichever comes first. As such, each layout group adds one GetComponent call to each child layout element’s dirtying process, making the nested layout groups extremely bad for performance.

Solution: Avoid layout groups when possible.

Use Anchors for proportional layouts. On hot UIs with a dynamic number of UI Elements, consider writing your own code to calculate layouts. Be sure to use this on demand, rather than for every single change.

Learn more about layout groups in our documentation.

출처 : https://unity.com/how-to/unity-ui-optimization-tips

0개의 댓글