- Home /
is hit.transform always the same as hit.transform.gameObject.transform
For RaycastHit, is hit.transform always the same as hit.transform.gameObject.transform
Well, they may return the same thing, but what is the processor having to do to find that?
Since this.transform is an external call to the underlying engine it is slightly better to use a cached variable. : from an answer to a question here : http://answers.unity3d.com/questions/314373/most-efficient-way-to-declare-and-assign-variables.html
Therefore you want to drill from a transform handle as little as possible. Step straight up to the gameObject for components, step to transform just for position and rotation.
Answer by nikescar · Oct 03, 2012 at 10:33 PM
It is the same. If you wanted (I don't know why someone would) you could even do something like: hit.transform.gameObject.transform.gameObject.transform.gameObject.transform or hit.transform.gameObject.rigidbody.transform.gameObject.transform.rigidbody.gameObject.transform
Just use hit.transform. ;)