Layout Group children and their anchors

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!

bump

Each of the layout group components have a “child alignment” field that should dictate the pivot that the child is positioned using.

Hi @LiterallyJeff

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).

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).

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.

5 Likes

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.

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.

This is issue is still valid though.

1 Like

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.

1 Like

2024 with Unity 6 and this is still an issue. Giving each Element in my Group a seperate child,that then can change anchors is not an option to me. If anyone found a solution, please let us know!

1 Like