Transform.transform...what?

Looking at the docs, the Transform component or its base classes do not have a transform member, so why in a Monobehaviour script can I call transform.transform an infinitesimal amount of times? It makes no sense.
Can someone point me to the docs where it explains this, in case I missed it?

Thanks.

There’s no explaination in the docs, it’s probably best not to use it like that though.

But why is it there? Why can I use it like that?
It just seems weird because its not documented.

I assume you mean “infinite”, since “infinitesimal” means “really tiny”. Anyway, Transform inherits from Component, which has a transform variable. The docs tell you what every class inherits from (if any) and what all the class variables are.

–Eric

1 Like

Thanks for correcting me. :sweat_smile:

Are you sure? I’m looking at http://docs.unity3d.com/Documentation/ScriptReference/Component.html and it makes no mention of a transform.

Seems to be a simple omission in the Unity 4.1 docs, since it appears in my local 4.0 docs, as well as the 3.5 docs, and, um, later-than-4.1 docs. :wink:

–Eric

So is transform.transform the same as transform.GetComponent().transform?

Not quite; transform.transform has the same effect as transform.GetComponent(Transform).

–Eric

Ah, thats what I meant. Thanks.

I’m no expert, but I wanted to add that I believe you should use transform.transform over transform.GetComponent(Transform). The latter has to perform some kind of operation (not sure what it is, maybe a series of string compares?) in order to find “Transform”, while the former is simply accessing the field of a field in your script. Accessing the field should be faster.

why would you ever even need to go to transform.transform, just use transform…?

Correct, just use transform; you would never need to use transform.transform. It’s true that you’d prefer transform over GetComponent(Transform), though the speed difference is small.

–Eric

Was just wondering why it was there and not in the docs. That is all.

Seems like the Component doc get messed up. I’m pretty sure there’s supposed to be a gameObject variable in there, too.

Yeah, as I mentioned, it’s been fixed, and it was correct before 4.1.

–Eric