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

    bibikonfikus1234

    Joined:
    Jan 31, 2020
    Posts:
    40
    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:
    upload_2024-1-31_16-52-46.png
    Of course, I can set spacing, but this will be working only for the current aspect ratio of screen:
    16:9
    upload_2024-1-31_16-53-23.png
    21:9
    upload_2024-1-31_16-59-48.png
    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:
    upload_2024-1-31_17-3-21.png
    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?