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.
  2. Dismiss Notice

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:
    36
    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:
    28
    this is the only thing that worked for me
     
  4. ianfan53

    ianfan53

    Joined:
    Jun 22, 2023
    Posts:
    1
    I encountered the same problem. I rebuilt the UI layout without using any Content Size Fitter components following Gresolio's suggestions and it now works perfectly. I highly recommend using Layout Elements to achieve the auto-sizing and responsive layout goal.
     
    sandolkakos likes this.
  5. JegoBestaatal

    JegoBestaatal

    Joined:
    Jun 30, 2020
    Posts:
    1
    Real life saver here, finally got my layout groups doing what they're supposed to be doing. Don't get why this is still such a problem, given the amount of people having issues with it.