Is rectTransform cached?

Simple, quick question - is .rectTransform cached in the same way that .transform is cached? I can’t find the answer anywhere.

did not think there was a .rectTransform i generally just cache my own in awake

private void Awake() {
    _rect = (RectTransform) transform;
}
1 Like

Yeah I can cache it myself, I’m just interested to know if I should cache it!

I doubt such behavior would be documented. It would be a needless implementation detail that would change nothing about the API’s intended promise, which is to give a shortcut to the RectTransform component.

Well sure, I get that. There was discussion about the same thing with .transform back during the Unity 4/5 days, so I thought it was worth asking!

Anyhow, turns out I was being a bit dense and .rectTransform is just a property of the UI Image type, which is where I was grabbing it from.

that explains the confusion, since i did not see it anywhere. in that case i would assume its cached since that component would need to know the rect transform. but also i would cache my own, instead of doing through a other component to get it.

I was surprised by this too. It’s actually the UI Graphic type, which a few things inherit from (like Image and Text), which has this handy shortcut.