fontSizeUsedForBestFit return 0

Hi,
I have an issue and do not find what is wrong. I want all my texts in my project to have the same text size. To do so I have a canvas scaler set to match height and a UI.Text with best fit tick inside.
I want to get the size of this text then destroy it and apply the same text size to all other text. The issue is that GetComponent(UI.Text).cachedTextGenerator.fontSizeUsedForBestFit return 0.

Thanks

Here is my code :

#pragma strict
var DefaultTextSize;

function Start () {
	var TextSize = GameObject.FindWithTag("textsize");
	DefaultTextSize = TextSize.GetComponent(UI.Text).cachedTextGenerator.fontSizeUsedForBestFit;
	Destroy(TextSize.transform.parent.gameObject);
	Debug.Log(DefaultTextSize);
}

Old question but I’m posting this answer for next persons. I found similar question:

@andreimarks said: “I had the same issue, and it looks like cachedTextGenerator won’t return the proper information until the next frame.”

That really helped, but in my case wait to second frame didn’t work. I realized that cachedTextGenerator sometimes updates even in 2-3 frames after text change. My solution is that simple loop (C#):

IEnumerator _wait() {
	while (label.cachedTextGenerator.fontSizeUsedForBestFit == 0)
		yield return new WaitForSeconds(0);
	// Do something...
}

I came here with the same problem and the answer with the while loop didn’t work. I realized that you need to get the size of the text at the end of the frame. So here is my code

void Start()
{
    StartCoroutine("SetSize");
}

IEnumerator SetSize()
{
    yield return new WaitForEndOfFrame();
    int sizeAux = texto.cachedTextGenerator.fontSizeUsedForBestFit;
    //Do staff
}