In terms of seaching the scene, as examplified in the documentation, a question about efficiency is raised. Efficiecy in this context meaning searcing through the least possible gameobjects.
Will .Find(“/name”) only search through the “grand parents” of the scene?, or does it just discard all the other object as it searches through them?
EDIT:
Just a reformulation of the question.
Which is less expensive? .Find(“name”) or .Find(“/name”). When one needs to find a gameobject without a parent, in the scene hierarchy?
I am looking for a “Code-Shark” that know of the searching algorithm, and definitively can say if anything is gained from using .Find(“/name”) over .Find(“name”) in the aforementioned scenario.
From what I know, using Find(“/name”) will only search the exact path written only inside the hierarchy where the script is attached.
Using Find(“name”) will look the whole scene and hierarchies, and is expensive. Should be avoided.
The ideal use would be FindObjectsWithTag(“tag”) returning all gameobjects with that tag assigned, no matter their name.
Or even, if you’re searching for a partiular component inside the object, you could use GetComponentsInChildren(), after you get all the objects, or if the objects are inside the script’s object.
.Find(“/name”) will find anything that doesn’t have a parent, as the document stated, so it is root if you will. Not specifying the hierarchy(with slashes) in the Find will search regardless of the relationship of the objects.
Also it seems reason that the back end code that Unity did for the find method, if searching based off not having a parent, this would be more efficient because if the root/top most parent doesn’t match the find criteria, it will just move on. If left open, it would most likely iterate over the child of object n, rinse repeat, which would take more time since it can’t really skip.