- Home /
Difference between hit.collider.gameObject vs hit.transform.gameObject
For a hit from RaycastHit, does it matter if you reference the gameObject via hit.collider.gameObject or hit.transform.gameObject? Does one not give you access to the meshfilter or something? Is there a difference between the two references?
Answer by Dreamer · May 16, 2011 at 01:31 AM
There is no difference. They both return the same thing.
He probably know that they return the same thing; the question is "what is the difference"; is one better than the other? Faster? Less overhead?
Answer by darshie1976 · Mar 25, 2016 at 05:52 PM
They seem to be interchangeable; although I suspect that transform is better, since in many talks about performances, every one is more inclined to suggest to use the transform component, to access to children of a GameObject.
So maybe also the search for the parent is faster with transform?