How to lock element width or height in a vertical or horizontal layout?

I want to achieve the following for a group of buttons within a horizontal layout group but have been completely confused by the documentation that is provided:


I want to be able to lock one item, lock one element or limit the max width of an item whilst the others are flexible or free to resize their width. I believe that this would work the same with all of the layout scripts, Horizontal Layout, Vertical Layout and Grid Layout

Rather unintuitively this is how it actually works.

You need to first make sure that your GameObject with the Horizontal Layout Group applied has Child Controls Size checked for “Width” and “Height”. You then need to have Child Force Expand “Width” = unchecked, “Height” = checked.

Locked Item: Needs a Layout Element script added to it.

  • Preferred width: set to the value you want.

  • Flexible Width: 0 (if it’s left at 1, it’ll just be flexible with 100 added to it and yes you have to check a box for “flexible” when you want it to not be flexible)

Flexible Item: Needs a Layout Element script added to it.

  • Flexible Width: 1

If you leave the Flexible Width off, it will just collapse the button’s width.

The results are consistent once you get the hang of it, but the problem is bending your head to click on all the different settings with names that don’t fit to get the right numbers.

Be careful if you’re going to use this for a Vertical group to set Child Force Expand “Width=checked” and “Height=unchecked” on the layout group