Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Force Immediate Layout Update

Discussion in 'UGUI & TextMesh Pro' started by kromenak, Dec 8, 2015.

  1. dimzki

    dimzki

    Joined:
    Apr 17, 2018
    Posts:
    12
    This works on my case (Unity 2021.3.10f1)

    Code (CSharp):
    1. IEnumerator RefreshUI()
    2.     {
    3.         yield return new WaitForEndOfFrame();
    4.      
    5.         _horizontalLayoutGroup.SetLayoutHorizontal();
    6.         LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)_horizontalLayoutGroup.transform);
    7.     }
     
  2. grrava

    grrava

    Joined:
    Nov 11, 2012
    Posts:
    33
    Chiming in, this is the only thing that worked for me (tried all the above solutions and others):

    Code (CSharp):
    1. private IEnumerator ForceUpdateLayout(Component panel)
    2. {
    3.     var layoutgroup = panel.GetComponentInChildren<LayoutGroup>();
    4.     if (layoutgroup != null)
    5.     {
    6.         yield return null;
    7.         layoutgroup.enabled = false;
    8.         layoutgroup.enabled = true;
    9.     }
    10. }
    It's baffling that this is still such an issue in a product that exists for years... (Unity 2021.3.11f1)
     
  3. LexaMV

    LexaMV

    Joined:
    Feb 20, 2018
    Posts:
    25
    this is the only thing that worked for me