Unity 5.x Where are the Getters methods?

Hello,

Why the getters methods were remove from classes? I have notice that the only one that still have a geter method is the transform. So now I have to use GetComponent all time? This use reflection? so is more cost to process?

Regards.

There is also ‘gameObject’ :wink:
Yes, GetComponent<> is the way to go; which you can cache, of course.
I doubt this uses reflection.
Why they were removed, I’m not sure. Maybe because of the generic GetComponent, not sure.
Lastly, I don’t think there’s anything for you to worry about :slight_smile:

To reduce inter-dependency in the API.

Not all the time. If you’re just getting local references then you get it once and cache it - which is exactly what those convenience properties were doing anyway.

To clean up the classes (both GameObject and Transform). For example, there’s no guarantee that every GameObject would have an animation component, so it doesn’t really make sense to keep an animation getter there anyway.

GetComponent is a more generic way to get components you need anyway. Plus, if you want to bring back getters, you can always roll your own classes. I’d recommend caching them though.

https://blogs.unity3d.com/2014/06/23/unity5-api-changes-automatic-script-updating/

The getters were just doing GetComponent anyway. If you wanted the best performance you would have been caching the references regardless of whether you were using the getters or not, so no changes there.

–Eric

thank you guys, for your explanations.