Instantiating a prefab.


I was reading documentations for Instantiation and I couldn’t help but notice that when they want to store a reference to the prefab, they use transform type, rather than GameObject, is there a reason to do it?

For example, they define a public transform property and drag and drop the prefab on it and it just gets it’s transform component, then they use it to instantiate that prefab in the code where it seems natural to me to define a GameObject field instead.


If you’re going to be referring to the Transform component mostly then it makes more sense and is more efficient to instantiate it as a Transform. You can still get at the “GameObject stuff” (name etc.) if you need to.