- Home /
What is more efficient?
Making an static reference of the GameObject A and using it from some scripts or using GameObject.FindGameObjectWithTag("A tag") from every script.
Thanks in advance.
@vikiller5 - you could google for "unity GameObject.FindGameObjectWithTag performance" - You'll find some threads and articles. Anyway, I have an impression that all the Find and GetComponent are relatively "heavy" and when possible should be cached to some field in Start / Awake methods. BTW, your question topic is really vague, it doesn't mean anything to someone browsing questions.
Hi, thanks for answering, and as you said the find methods seems to be pretty heavy, but i wanted to know if it is worth making static variables. Sorry about the topics, I edited them.
Answer by JVene · Aug 29, 2018 at 06:55 PM
No doubt, make the variables. The choice of static or member depends on design. If there are just a few objects of interest, then a few static variables may be useful, but they must still be a member of some class, static as they are, and they'll have to be 'located' in some fashion during initialization (perhaps Start or Wake). My own preference is to have the Start or Awake method of the object(s) of interest 'register' themselves, which avoids a 'find' method at initialization.
At best, 'find's performance is dependent on how many objects are to be searched, and, of course, the device on which the software is running, but you can expect at most a few thousand per second on some platforms and conditions, while it might reach up to 100,000 per second on a PC or console. That may seem fast, but on that same platform a static or member reference to that same object may operate on the order of close to a million per second (could be a few million per second). When inside an Update or FixedUpdate, that really adds up to performance drain and, on mobile, battery drain.
Your answer
![](https://koobas.hobune.stream/wayback/20220612173729im_/https://answers.unity.com/themes/thub/images/avi.jpg)