Search Unity

Question How to determine final dimensions of elements within a VerticalLayoutGroup

Discussion in 'UGUI & TextMesh Pro' started by Atrapos, Feb 4, 2024.

  1. Atrapos


    Sep 6, 2020
    Mobile application, I have a canvas on the root which has a VerticalLayoutGroup. It contains 3 layout elements , a top, middle, bottom. The middle will stretch to fit screen height. How can I determine the height of this middle element in code? I wish to instantiate objects within this region with random X/Ys, and not have them fall outside the middle element, but I can't determine the rendered width and height of this.

    I see this is calculated and known within the engine, because the inspector shows me the correct height of the middle element, thought it states the value is driven by vertical layout group. But in code, all rects, anchors, mins maxes, appear to be 0,0,0. The only element that appears to have any size information is the canvas on the root.

    I have found numerous threads answering this question for other people, but the only difference I can see is I am using layoutgroups and they are not.