Game Tech Blog

강제로 레이아웃 업데이트, LayoutRebuilder.ForceRebuildLayoutImmediate() 본문

Unity

강제로 레이아웃 업데이트, LayoutRebuilder.ForceRebuildLayoutImmediate()

jonghow 2023. 3. 21. 21:04
반응형

상황

Contents Size Fitter 컴포넌트를 쓰면서 내부 내용이 변경될때 그 순간에 바로 업데이트가 되지않는 버그가 있다. 

예제는 Layout 하위에 이미지와 텍스트를 둔 후에 텍스트 내부를 가변형으로 구성하면 예제 구성이 가능하다.

 

[gif] 문제점1
[gif2]문제점 해결방안

원인

이런저런 자료를 찾아봤지만, 뭔가 버그라고 생각되지만 버그라는 얘기는 찾지못했다. 

일단 내가 원하는대로 쓰는게 중요해서 원인은 찾게되면 추후에 서술하겠다.

해결방법 ( Solution )

가장 대표적인 방법은 아래 함수를 사용한다.

LayoutRebuilder.ForceRebuildLayoutImmediate(RectTransform LayoutRoot);

 

[gif] 최종 해결

참고자료

https://docs.unity3d.com/2018.1/Documentation/ScriptReference/UI.LayoutRebuilder.ForceRebuildLayoutImmediate.html

 

Unity - Scripting API: UI.LayoutRebuilder.ForceRebuildLayoutImmediate

Normal use of the layout system should not use this method. Instead MarkLayoutForRebuild should be used instead, which triggers a delayed layout rebuild during the next layout pass. The delayed rebuild automatically handles objects in the entire layout hie

docs.unity3d.com

 

 

반응형
Comments