Search Unity

Layout Group children and their anchors

Discussion in 'UGUI & TextMesh Pro' started by jhow77, May 12, 2017.

  1. jhow77

    jhow77

    Joined:
    Jan 10, 2017
    Posts:
    19
    I'm currently making a UI Menu. I'd like to the use layout groups to place and space children. But, the layout group is forcing the anchors of its children to be the top left corner of the layout group.

    I don't want the anchors of the children to be the top left corner of the layout group because I'd like to set the anchors manually to design for multiple resolutions.

    Is there a way to address this issue? Or do I need to just avoid using layout groups?

    Thank you!
     
  2. jhow77

    jhow77

    Joined:
    Jan 10, 2017
    Posts:
    19
  3. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Each of the layout group components have a "child alignment" field that should dictate the pivot that the child is positioned using.
     
  4. jhow77

    jhow77

    Joined:
    Jan 10, 2017
    Posts:
    19
    Hi @jeffreyschoch

    From my understanding and testing, it appears as though setting this field does not update the anchor min and max positions. Just the child position inside the layout group. The anchor positions still appear to be the same top left position.

    It appears as though the layout group is both:
    1. Forcing min anchor == max anchor
    2. Forcing both the anchors to be top left corner

    I'd like to be able to set the min and max anchor positions to different positions (where min anchor != max anchor).
     
  5. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    This is the expected behavior, as LayoutGroups are full in control of the size and position of the child elements. You would set the anchors on the LayoutGroup object, and have the LayoutGroup itself be dynamic with resolution, which then sizes and positions the children accordingly.

    If you want some other custom thing, you could try getting fancy with the LayoutElement component, along with putting each child object inside an empty parent GameObject. I believe the parent will be affected by the layout group's controls, but the child will still be able to have customization. ContentSizeFitter on the parent may be desired to have the LayoutGroup know how big each child is (ContentSizeFitter may need to be accompanied by a LayoutGroup component, even if it's just for one child).
     
  6. Carocrazy132

    Carocrazy132

    Joined:
    Aug 16, 2015
    Posts:
    15
    I find this solution to be hacky and completely unsatisfactory. If that's the expected behavior, then it's expected to not work, and I'm expected to make workarounds or code my own UI components which do what they should have done in the first place, which I'm beginning to find is more often the case than not with Unity UI as we move forward into later and later versions without anything being fixed.

    Using a layout group should not completely break our ability to use anchors. LayoutGroups can be in full control of the size and position of elements without modifying how we reference the anchor position. They reset the anchors so that the math would be easier on their end. This is a default Unity UI control and what I expect is for it to work fluently with the Unity UI system.
     
  7. Stephaniecheng14

    Stephaniecheng14

    Joined:
    Sep 15, 2020
    Posts:
    2
    Still looking for a solution for this...
    I'm having the exact same problem with not being able to set the anchor point of a child of a vertical layout group. It seems as if the vertical layout group constantly sets the anchor points to the top left but I can't find a way to change that.. Please let me know if anybody finds a way to fix this.
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,481
    Please note that the subject here is UI but it's on the 2D forums. There's a dedicated UI forum for the UI team here where you're likely to get more focused eyes on it.

    Also note that this post seems to be replying to an original post in 2017. Again, this forum is predominently related to features put out by the 2D team so on the UI forum you're likely to get better info.
     
  9. tovabele

    tovabele

    Joined:
    Nov 4, 2016
    Posts:
    3
    This is issue is still valid though.
     
    _eternal likes this.
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,481
    Can you clarify what the point is of saying that? I don't see anyone saying the issue is invalid so I'm curious why you need to state it.

    I'll move the post to the correct forum so you can involve the correct devs.