(I tried to submit this as a bug report, but it froze at “Packing the report”
)
According to the latest online documentation at https://docs.unity3d.com/Manual/MobileOptimizationPracticalScriptingOptimizations.html:
“Little known fact: all of the component accessors in MonoBehaviour, things like transform, renderer, and audio, are equivalent to their GetComponent(Transform) counterparts, and they are actually a bit slow.”
This statement is followed by an example in which a .transform reference is replaced by a cached reference to the transform component.
However, according to an article posted by Lucas Meijer on the Unity Official Blog at https://blogs.unity3d.com/2014/06/23/unity5-api-changes-automatic-script-updating/:
“For Unity5, we decided to bite the bullet, and remove all the quick component property getters with the exception of .transform (since that one belongs in the core module, there’s no need for it to go, and it’s also by far the most used one)
[2] in Unity5 we also cache the transform component on the c# side, so there should no longer be a performance reason to cache the transform component yourself.”
Clearly the blog is somewhat incorrect, because the quick component references to .renderer, .light etc still work in Unity 5. But what about caching the transform - is it still best practice or not?!