How do I get the position of a RectTransform as if it were a direct child of the canvas?

Hi there!

I’m making some tooltips that are children of children of children of my Canvas, and I want to make sure they do not go off the screen, so I’d like to know the position of them as if they were a child of the Canvas itself.

I’m using Screen Space - Camera and Scale With Screen Size with a Reference Resolution of 640x360.

I’ve been googling and tried the functions in the RectTransformUtility, and GetWorldCorners, but I can’t seem to get the coordinates I need.

The funny thing is, I know Unity must have a simple way of doing this because if I drag the object in the hierarchy to be a child of the Canvas, it will autocalculate exactly the coordinates I want. With that in mind, I could simply change the parent and then get the rect at that point, then change the parent back. But that seems wildly inefficient, and there must be a way to get what I’m looking for.

Thanks for your time and I appreciate any input!