- Home /
Accessing children of instances vs children of original prefab
It looks like there is a major difference in accessing a child object using:
mainObject.transform.Find("Child");
vs
mainObject.Find("Child");
It looks like the first will access the children of the instance, and the second will access the children of the prefab (but not the instances)? Is that the main difference?
Answer by luizgpa · Jan 04, 2012 at 03:19 PM
Are you using UnityScript and is mainObject a GameObject?
If that is the case, the first is calling the method Find from transform, while the second is calling the static method Find from GameObject class. The differences are:
1 - the 1st is a method from a Transform instance and the 2nd is static method from GameObject
2 - the 1st returns a Transform and the 2nd returns a GameObject
3 - the 1st searches in the children of the given transform, while the 2nd searches in all the scene
Can you explain the difference between a static method from GameObject and Transform instance? Does one access the original prefab, vs just an instance?
If mainObject is GameObject when you call mainObject.Find("Child") it actually calls GameObject.Find("Child"). In C# it would be an error because a GameObject doesn't have a Find method.
The main difference is #3. If you 4 objects with the same name GameObject.Find() will return the same one no matter from where it was called.
Hmm I guess this means that there is no difference between the original prefab and its instances