- Home /
Unity 4.6 - VerticalLayoutGroup
This is about the built in VerticalLayoutGroup component in Unity 4.6.
It works fine in most cases, however in certain cases it's not working for me at all - it positions everything at the same point.
Reproduction steps:
Instead of adding children to the LayoutGroup that are Images or Text add an empty gameObject and add Images or Text to that object.
So instead of:
VerticalLayoutGroup
- Image1
- Image2
- Image3
Have this:
VerticalLayoutGroup
- GameObject with no components attached (doesn't make a difference if RectTransform)
-- Image1
- GameObject
-- Image2
- GameObject
-- Image3
(The dashes indicate the level of nesting).
Now all the images will be positioned at the same place. This makes sense in a way because the container GameObjects do not have LayoutProperties which you can see on any widget gameObject.
So my question is: How can I use VerticalLayoutGroup with children that are not widgets and that have their own widget children?
The use case is this:
I'm displaying a form that has rows of controls, each row consists of an image and text. And the text should be free to expand. If it does expand it should push the rows down below it.
VerticalLayoutGroup (form)
- GameObject
-- Image1 (CheckMark)
-- Text
- GameObject
-- Image2 (CheckMark)
-- Text
- GameObject
-- Image3 (CheckMark)
-- Text
Thanks.
Answer by Suttonian · Oct 06, 2014 at 03:49 PM
For now it seems the best method is to attach a LayoutElement to the GameObject, and create a script that will update its Preferred Height based on its content size.
Answer by Bunny83 · Oct 06, 2014 at 04:21 PM
Well, there are several ways i guess. The most obvious would be to turn your empty gameobjects into HorizontalLayoutGroups.
Your answer
![](https://koobas.hobune.stream/wayback/20220613164339im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Rotate GameObject using Coroutine 2 Answers
Trash Collection For Instantiated Game Object 1 Answer
C# Rotate GameObjects Regardless of List Size 2 Answers
Assigning a GameObject to a class 1 Answer