Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by screenname_taken · Feb 23, 2014 at 05:12 PM · performancetag

find with tag VS find with name.

Hi, i know that finding a gameobject by using its name is resource intensive as it checks every object 'till it finds it. Also know that it's a cardinal sin to put that in Update().

My question is, is it better to try and find something by its tag instead? Does it still check every object for its tag or does it have a list with the tags and checks only the objects with that tag?

thx.

Comment
Add comment
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

2 Replies

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

Answer by mayorc1978 · Feb 23, 2014 at 07:39 PM

Yes it's better to search by Tag, it should be more optimized, moreover when you have a large number of objects in general and only few with specific tags.

If timing it's not striclty important you can define custom timing for search method, using a Coroutines with specific time interval. Update() method will do this each frame, with a Coroutine you can do it every half second or less, you choose.

Anyway remember in most case you need to find an object once, maybe in the Start() method, and then you can cache that reference and use that directly. This last case is usable for GameObjects components too. Caching and pooling is the key to optimization for scripts. And it's usually the most ignored.

Comment
Add comment · Show 2 · 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
avatar image screenname_taken · Feb 23, 2014 at 07:45 PM 0
Share

Thx. Yeah i'm using find only in start, but i want to make even that as best as possible. I had a few things that are common in multiple scenes, so i wanted to find them by script (In case i forget to assign them in the editor) from the various objects that needed them. So i thought of parenting them under an empty object with a tag, finding just that by scripting in Start(), and then moving to its children.

avatar image mayorc1978 · Feb 23, 2014 at 08:11 PM 0
Share

You can even write an Object$$anonymous$$anager that checks consistency in each scene and that do the work for you, but depends on the level of complexity of the scenes, and the time needed to write that Object$$anonymous$$anager too.

avatar image
1

Answer by Zentiu · Feb 23, 2014 at 09:51 PM

I cant be sure but look at tags as boxes like you see variables in your script.

unity already knows who has what tag when you assign it to them.

so if you have like 5 gameobjects with the "NPC" tag and 10 with the "enemy" tag and you want to look inside objects with enemy tag, he will only look through 10 gameobjects.

don't quote me on it though but personally I prefer tags.

Comment
Add comment · Show 1 · 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
avatar image screenname_taken · Feb 23, 2014 at 09:56 PM 0
Share

It's also what i also understood so far, but i wasn't sure my self.

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

21 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

Related Questions

Is it okay to assign and 'un-assign' game object tags at runtime, will it come back to bite me? 0 Answers

ArrayLists or Tags? 1 Answer

General programming question on Static Classes 1 Answer

Performance hiccup on initial contact with rigid bodies 0 Answers

How can I easily implement performance statistics grabber? 1 Answer


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