Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Layout Group content equal size

Discussion in 'Unity UI & TextMesh Pro' started by Julien_at_work, Oct 12, 2018.

  1. Julien_at_work

    Julien_at_work

    Joined:
    Aug 9, 2018
    Posts:
    10
    Hi,
    What i have:
    Vertical Layout Group
    --Horizontal Layout Group
    ----TMP Text x2
    --Horizontal Layout Group
    ----TMP Text x2
    --Horizontal Layout Group
    ----TMP Text x2
    All the TMP Texts have autosize toggled on.
    My problem is, that i can't find a combination of settings that equalizes the heights of the horizontal layout groups inside the parent vertical group. Some combinations seem to almost produce the desired result, but the horizontal groups still differ by some small amount which makes the autosize text vary slightly between horizontal groups in turn though.

    What i want:
    The horizontal groups should all have equal sizes, auto expanding with the parent vertical group. The TMP-texts should then autosize to fill each horizontal group.

    The problem seems to come from when i add the horizontal groups which grow larger with their text content. A single TMP text works fine and doesn't affect its parent

    How do i achieve that?
     
    Last edited: Oct 12, 2018
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    486
    You might try adding a LayoutElement component to each horizontal group to override its preferred height, to ensure the preference is the same on all of them. (And presumably you'll need to make sure "force child expand" is checked in the vertical layout group.)

    Alternately, if there will always be 3 horizontal layout groups, and you always want them to have an equal share of the space, then you don't need to use a vertical layout group at all! Just set the horizontal groups' Y anchors to be 0 - .33, .33 - .67, and .67 - 1 and their top/bottom to all be 0 relative to the anchors, and they'll automatically stretch with the parent.
     
  3. Julien_at_work

    Julien_at_work

    Joined:
    Aug 9, 2018
    Posts:
    10
    Thanks, the second option was kind of what i was looking for. It's not dynamic and a lot more work the more children there are, but it works in my specific case.