VerticalLayoutGroup not responding to child size changes

I have expandable children within a VerticalLayoutGroup but it seems the layout groups do not respond to child size changes nor can be easily pursuaded to in code except by disabling and enabling them! (
layoutGroup.enabled = false; layoutGroup.enabled = true; )
Is this the only way?

Also would be nice if a layoutgroup could control its RectTransform size so if being used in scrollview content it controls the size of the content area.

Also the ‘Child Controls Size’ and ‘Child Force Expand’ - I think the correct way to read them is Control Child Size and Force Expand Children, but as per above if you could have Children Control Size it would be useful

1 Like

well had to write own version of VerticalLayoutGroup to handle this

    RectTransform rt;

    public override void SetLayoutVertical()
    {
        SetChildrenAlongAxis( 1, true );
        //resize gameObject (content in scrollview) to height of layout
        if (rt == null) rt = GetComponent<RectTransform>();
        rt.sizeDelta = new Vector2( rt.sizeDelta.x, GetTotalPreferredSize( 1 ) );
    }

    //allow update/SetDirty calls
    public void Resize()
    {
        SetDirty();
    }

Hello,
I had these issue for so long time and find these solution:

this.InitUI();
this.ContentSizeFitter.enabled = false;
this.ContentSizeFitter.SetLayoutVertical(); // can use SetLayoutHorizontal as well
LayoutRebuilder.ForceRebuildLayoutImmediate( this.RectTrans );
this.ContentSizeFitter.enabled = true;

So you need to stock your ContentSizeFitter and the RectTransform but it works properly.

1 Like