Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Controlling the Width of Child UI Objects

Discussion in 'UGUI & TextMesh Pro' started by Drakkith, Aug 28, 2023.

  1. Drakkith

    Drakkith

    Joined:
    Nov 29, 2016
    Posts:
    57
    Hey all. I'm real new to UI work and I've got a Shop window for my game that is giving me issues. I'm trying to get a two-pane window with clickable items on the left, and an item description and buy button on the right.

    I'm having trouble getting the sub-components of my left window to fit correctly. I have a vertical layout group component on a parent object and several UI objects as children of this object. Each of the children have another UI object (an small image for the background of some text) which has an object with a text component as a child. These last two end up way larger horizontally than they should be, stretching out past the bounds of the first UI object in the tree and I can't seem to get them to auto-size correctly.

    It's all very confusing. Some objects can't have their sizes set because they are being controlled by other elements, but others apparent can? Can someone elaborate on what a layout group does? Does it only control the size of its direct children and not their children?
     
    Last edited: Aug 28, 2023
  2. Drakkith

    Drakkith

    Joined:
    Nov 29, 2016
    Posts:
    57
    I think I answered my own question. After more testing it appears that layout groups only control the size of their direct children. Going further wouldn't make any sense, as you may want to do something else with further children. Sorry if this is obvious, I was in the middle of dealing with multiple issues with my UI, some of which turned out to be unrelated to layout groups. Anyhow, I managed to get my size issues resolved by setting the last few objects in the tree to stretch. They now fit exactly how I wanted them to.