Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Layout group with space between, but keep children size?

Discussion in 'UGUI & TextMesh Pro' started by bibikonfikus1234, Jan 31, 2024.

  1. bibikonfikus1234


    Jan 31, 2020
    I want to have buttons with preferred width in horizontal layout group. upload_2024-1-31_16-52-4.png
    But, children in layout start placing in middle, instead of having evenly spacing between each other. I set "child force expand" for width to true, and then:
    Of course, I can set spacing, but this will be working only for the current aspect ratio of screen:
    As you see, buttons change their width, when the aspect ratio of the screen is changed. But I want to keep their width constantly. Aspect Ratio Fitter component on children doesn't work, due to it has no effect with layout groups. Each child has a Layout Element component with these settings:
    In Horizontal Layout Group, child alignment set to middle center, control child size width and height both enabled, use child scale both disabled, child force expand enabled for width only.

    I can reach needed behavior by custom script, that will calculate spacing by screen aspect ratio, but is there a solution with common UI components?