I’m trying to make a simple panel, where if one component of the panel is missing, the one below it takes its place and the panel resizes to the new vertical height. I’ve drawn up a stupid little png of what I’m trying to accomplish. Any help would be greatly appreciated ![]()
A content size fitter on a parent with a layout should achieve this. Turning off an gameobject will make it not count towards the size and thus adjust the stuff below it upward.
I was trying to get that to work earlier and failed. What other components do I need on the parent or children to get it to function correctly?
Try using vertical layout group.
https://docs.unity3d.com/Manual/script-VerticalLayoutGroup.html
Parent (with vertical layout group and content size fitter, play around with force child expand)
- Child 1 (with Layout Element, set preferred width and height)
- Child 2 (same as Child 1)
- Child 3 etc (same as Child 1)
Then hide/unhide the children to see parent’s height change.
I have the children moving into place which is exactly what I needed, but I cant seem to get the parent panel resizing when the children are disabled.
edit:Okay I’ve fixed all the problems I was having. Now is there a way to make the child panels expand and retract depending on its content as the parent object now does? I’ve been trying a bunch of different settings and I can’t seem to get the desired behavior.
It says I shouldn’t add a second content size fitter as it should be driven by the parent (which is working correctly) but the children don’t work the same.
Ok, so a lot of the answers above are correct but what you need is a combination of them really. (actually reading back @enchiridion had it right)
- The Vertical Layout Group will layout your content vertically, however, it will resize children to fit within it and take up the available space.
- A Layout Element Control will allow you to control the minimum and maximum size of a child element, so you can ensure the children remain the same size and override the Layout group. however, they won’t affect the parent RectTransform which will stay the same size.
- By Adding a “ContentSizeFitter” to the parent Rect (with the layout group) and sessing it to “Min” on the Vertical Fit", will cause the layout group to size up / down based on how many children fit within it’s container.
Parent Rect with VertialLayout and ContentSizeFitter

Child Objects with LayoutElements applied
And a final one with the middle child disabled using the above setup:
Hope that helps.
Curious as to what you are trying to achieve then?
You might want to check out the “Flow Layout Group” in the UI Extensions project (link in signature) which sounds like what you are after.

