P
P
Pavel2018-05-22 19:30:22
C++ / C#
Pavel, 2018-05-22 19:30:22

Why is RectTransform height = 0?

I need to make a diary page that will have 3-5 phrases depending on their size (it depends on the amount of text in UI.Text).
For convenience, I decided to use VecticalLayoutGroup with these settings
skrinshoter.ru/s/220518/kcMs35mX?a
By checking the box, the text began to adapt its height very nicely.
True, now we cannot manually manage it. But that suits me.
skrinshoter.ru/s/220518/i8KSfNum?a
I also made 5 UI.Text (all children of VerticalLayoutGroup), 3 of which are enabled by default, and the rest will be included if the first 3 phrases do not take up all the free space (for I consider all the space RectTransform.rect.height of the VerticalLayoutGroup).
The last step remains: calculate the current height of each Text, depending on the line that is placed in it. I do it like this:
skrinshoter.ru/s/220518/481bmNku?a
But the height of the RectTransform with the checkbox on the VecticalLayout is always 0. I turn it
off - I lose adaptability, but the height shows the correct one.
How do I get the height of a RectTransform if it's controlled by a layoutGroup?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel, 2018-05-23
@youkerni

The problem was that the size of the UI.Text container (when controlled by VLG) is calculated after some time.
Since the size of the container is not calculated immediately, a delay must be made.
At the beginning, I inserted the text into the container, made a delay in the coroutine, after which I got the correct sizes of the containers.
screenshoter.ru/s/230518/7xHp7RjU?a

F
freeExec, 2018-05-22
@freeExec

Use the Content Size Fitter component

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question