UI sizeDelta.y return 0 after instantiation

This problem has been buggering be for quite some while. I have found a solution, bet it’s not as clean as i’d want.

Here are examples.

private void Start() {
    GameObject node = (GameObject)Instantiate(contentPrefab);

    RectTransform rectComponent = node.GetComponent<RectTransform>();

    Debug.Log(rectComponent.sizeDelta.y.ToString()); //prints 0 ?
}


private IEnumerator Start() {
    GameObject node = (GameObject)Instantiate(contentPrefab);

    RectTransform rectComponent = node.GetComponent<RectTransform>();

    yield return new WaitForSeconds(0.1f); //wait for some small time
    Debug.Log(rectComponent.sizeDelta.y.ToString()); //prints actual value, not 0
}

Looks like UI elements are not updated on instantiation, but in fact left for update on next iterations.

Has anyone tried any workarounds, without using any update methods?

Solution is to wait a frame before UI element is actually initiated and positioned.
That can be done by:

yield return null;

yield return new WaitForEndOfFrame();

or set the element dirty and process it in fixedupdate.