Where do components get added in Unity?

by SanMalik   Last Updated December 06, 2018 11:13 AM

In unity's GameObject class, there are a few default data members. When we add a component to the game object, light for example, where exactly does it get added? Does it become a part of the GameObject class?

Tags : unity c# scripting


Answers 1


In the past, components used to be added to the GameObject itself, in such a way, that you could call myGameObject.renderer to get an object's Renderer.

This however changed to the call of myGameObject.GetComponent<Renderer>(), which hides the details of where the components are saved, which shouldn't be relevant anyway. Since for most (if not all) cases it doesn't matter for the user where components are, but that they belong to an object.

TomTsagk
TomTsagk
December 06, 2018 10:55 AM

Related Questions


How does Unity call "update()" in the scripts?

Updated April 23, 2015 21:05 PM

Instantiating prefabs dynamically in script

Updated April 08, 2015 18:05 PM

DontDestroyOnLoad() doesn't work in Unity

Updated April 14, 2015 20:05 PM

Questions about scaling in a 2d game in unity

Updated April 20, 2015 22:05 PM

Is it safe StringToHash() to use in Unity?

Updated May 17, 2015 21:05 PM