How to measure dimensions of Label or RichText after instantiation

I’m trying to some dynamic creation and positioning of rows of text, and since some of the text will be multiline and will wrap differently based on screen width, I’m trying to figure out how to measure the height of Labels and/or RichText at runtime.

Has anyone dealt with this before? Thanks!

Actually, I just figured it out - after instantiating and setting the parent for the label/richtext, I can get the UITransform’s height immediately without having to wait for the component to get rendered or anything like that.

const node = instantiate(somePrefabWithRichText);
const richText = node.getComponentInChildren(RichText);
console.log(richText.getComponent(UITransform).height);