- Home /
GameObject.FindGameObjectWithTag and Transform.Find
I have watched a few of the tutorials located here in the "Learn" section of the website and on several occasions the instructors mention how "expensive" GameObject.FindGameObjectWithTag can be and that it is not a recommended way of referencing game objects.
I was reviewing the API and came across the Transform.Find method and I got curious whether it is a better solution to GameObject.Find or if it is just as "expensive" as the latter? I am curious because I noticed that when using Transform.Find you explicitly tell the component what game object to search within by using string format to specify a path, even if your game object is a few children down, whereas I think the reason GameObject.Find has to gather all game objects and sort through them via comparison.
It would make sense to me that Transform.Find would be a better solution if this were the case, but I am hoping to get some confirmation.
I tend to stay away from all of them, but If I did have to use them, I would do so in Awake/Start and make sure to save off the reference. The expensiveness happens when people use them in Update() and are constantly using Find every frame.
it's not better or worse. one looks for a gameobject, the other down the path of the current one.
and for the expensive part. Try getting your frames done with these. if you manage to do that, you should probably cache some lookups, but until you get there, just use it.
along with mentioning expressiveness, premature optimization should be mentioned too. don't slow yourself down unless necessary.
Answer by dbchest · Dec 03, 2018 at 10:46 PM
I mean, I know enough about coding and Unity's API that I would never place one of those functions into the update message; I like to think I have established good coding conventions and as such I am faithful in using the Awake message when I feel like I need these functions are the best way to declare my references.
I suppose I may be reading to deeply into what I was hearing; I doubt I will ever encounter any true performance setbacks from doing things the way I do.
thanks for chiming in guys, everyone here as been awesome at answering my questions.
Your answer
![](https://koobas.hobune.stream/wayback/20220612183254im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I make a Gui button appear after the camera moves to a specific view? 0 Answers
Why does this wont work? transfor.find() 1 Answer
How to Find GameObjects after Scene Load 0 Answers
GameObject.findGameObjectsWithTag returning empty? 1 Answer
How to resort to another object if one is not found? 1 Answer