Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by vikiller5 · Aug 29, 2018 at 05:53 PM · tagreferencestaticefficiencyefficient

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eses · Aug 29, 2018 at 06:00 PM 0
Share

@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.

avatar image vikiller5 eses · Aug 29, 2018 at 06:11 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

88 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Set reference to multiple gameobjects based on tag category / multiple tags? 2 Answers

Static and Coroutines help 2 Answers

how faster is Static Function 1 Answer

Using Tag to find Child and execute Scripts 1 Answer

Do you have to set a object reference for every script? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges