How to get the width + height of a RectTransform controlled by a Grid Layout Group?

There is a RectTransform being controlled by a Grid Layout Group or some other Layout Group, because of this, the sizeDelta, anchorMin/Max, offsetMin/Max, rect, members all return 0, 0 but in the Inspector it does indeed show the width and height for the transform, but it is inaccessable.

I want to be able to get the w + h without knowing if the RectTransform is being controlled by a layout group.

Can anyone help? Thanks!

i see this is old and i was searching for a better answer myself. The problem is that the Unity UI doesn’t know the size until all the elements are drawn (which with a grid makes no sense but whatever) so you can use a coroutine with a 1 frame delay to wait for the draw and then get the values from the rect.

using UnityEngine;
using System.Collections;

public class GridElementWidth : MonoBehaviour {
	
	private float width;
	private RectTransform rt;

	void Start () {

		rt = GetComponent<RectTransform>();
		setWidth();

	}

	private void setWidth () {
		
		StartCoroutine(delayWidth());

	}

	private IEnumerator delayWidth () {

		yield return 0;

		width = rt.rect.width;

	}

}

transform.parent.GetComponent().cellSize

I have the same problem