Universal Method of finding pixel dimensions of UI elements

Assuming we’re considering UI elements nested under a screen-space overlay canvas. Is there a universal method of getting the exact dimensions of an element E in pixels?

Please consider all the possible cases:

  • All possible anchor settings
  • All possible pivot settings
  • Elements that are children of a
    layout group
  • Elements that contain content size
  • The Canvas has different UI scale modes

I’ve tried all the built in methods/variables with RectTransform and none of them seem to work for all cases. Is there an easy method to get the pixel dimensions?

Ok, so the real cause of my inability to do this correctly came from the fact that UI elements with content size fitters need 1 frame to update after children are added to them before you can accurately get their sizes. Knowing this, you can just use RectTransform.rect to get accurate coordinates (assuming you do so one frame after adding anything to the element).