Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Why the "source image" field will result the failure vertical layout group?

Discussion in 'General Discussion' started by breylinlee, May 24, 2023.

  1. breylinlee

    breylinlee

    Joined:
    May 4, 2019
    Posts:
    10
    test1:

    empty parent gameobject in Canvas: vertical layout group component(control child size: height )

    child gameobject A: image component (No Source Image), layout element component (flexible height:1)
    child gameobject B: image component (No Source Image), layout element component (flexible height:1)

    outcome: the two child gameobjects automatically adjust their heights to the same

    -----------------------------------------------------------------------------------------------------------

    test2:

    empty parent gameobject in Canvas: vertical layout group component(control child size: height )

    child gameobject A: image component (Custom Image Sprite), layout element component (flexible height:1)
    child gameobject B: image component (No Source Image), layout element component (flexible height:1)

    outcome: the gameobjectA is obviously larger than gameobject B. If I change the source image of gameobject A to something else, the gameobject A could even occupies the whole space of the parent, resulting the gameobject B disappears.

    -----------------------------------------------------------------------------------------------------------

    my question:

    Why the source image can influence the vertical layout group? I have set their flexible height to both 1, and I exepcet them have the same height. How can I do that?
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,553
    Take your layout rect, start increasing its height, see what happens. Basically, grab bottom edge and start dragging it down.

    Flexible Height does not mean the height will be distributed equally, it means the widgets will try to expand equally if there's empty space.

    For example, if you put another "white rect" before "Matrix Code", then the "matrix code" image will be always in the middle of layout group.
     
  3. breylinlee

    breylinlee

    Joined:
    May 4, 2019
    Posts:
    10
    Thank you for telling me how to observe their changes in the layout intuitively. With your hints, I also looked up the official documentation on "layout elements" and found it to be helpful.

    ·First, the layout controller allocates the minimum size properties (Min Width, Min Height).
    ·If there is sufficient available space, the layout controller allocates the preferred size properties (Preferred Width, Preferred Height).
    ·If there is additional available space, the layout controller allocates the flexible size properties (Flexible Width, Flexible Height).