Hello! Thank you, TMPro is great complex system
- Unity 2019.2.2f1
- TMPro 2.0.1
When I need to resize background to fit it to text, I use TMP_Text.GetPreferredValues(), and What is strange for me - that if DeepProfile doesn’t lie, it make doubled work. CalculatePreferredValues() execute in two paths.
My questions are:
- can I somehow optimize this process?
- maybe there’s another function in TMPro, that calculate sizes and get it to me?
In order to calculate the Preferred Values, an horizontal layout pass first occurs to determine the preferred width and then using the results of this horizontal pass, a vertical layout pass is needed to determine the preferred height. See the following and section related to Layout Calculations.
The preferred height cannot be computed without a horizontal pass first.
I did make some minor tweaks to this in the latest release which is version 2.1.3.
Accessing the text components, TMP_Text.preferredWidth and TMP_Text.preferredHeight should avoid doing layout passes provided the text properties have not changed. Ie. it would return the cached values.
1 Like
Thank you for fast answer. Where possible, I should use preferredHeight / Width, got it.