Hello,
I am creating my first project in Unity. I had a hierarchical game object and wanted to access its components from a script. It was difficult to me to find the correct way to do it. Firstly I found GameObject.Find, which looked promising and seemed to work, for example:
GameObject textContainer = GameObject.Find("TextContainer");
… but as soon as I converted my hierarchical game object into a prefab and started replicating it, I realised this search is global and not local to the current game object as I firstly thought, so all instances of my prefab were retrieving the same textContainer game object. Honestly it is logical because this call does not receive the current game object in any way, but the documentation is not clear about that and I could not find a better way to get the objects in my hierarchy. The only way GameObject.Find serves for this purpose is passing to it the full path to the game object I am looking for, which is not very friendly:
GameObject textContainer = GameObject.Find("/" + gameObject.name + "/TextContainer");
The examples provided in the documentation page for GameObject.Find do not help a lot either, as they are not explained, so I think explaining in detail all use cases would be very helpful.
After searching a lot I finally found this answer, which provides me exactly what I want: a search local to the current game object. A link to this page, from the one for GameObject.Find, would be very helpful as well.
Those are my thoughts . Thank you very much.