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
6
Question by daenor · Apr 10, 2013 at 08:19 PM · gameobjecttagtagsfindwithtagfindgameobjectwithtag

difference between GameObject.FindGameObjectWithTag(Tag tag) and GameObject.FindWithTag(Tag tag)

i've been wondering what the difference between these 2 is. I've seen them both appear and they seem to do exactly the same. The best explaination i could come up with is that the code got rewritten and they didn't remove the old function. Also there is no information whatsoever on GameObject.FindGameObjectWithTag(Tag tag) in the referece manual.

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

3 Replies

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

Answer by jiteshvm · Apr 10, 2013 at 08:29 PM

they both do exactly the same thing.

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 daenor · Apr 10, 2013 at 08:41 PM 1
Share

so also no coding difference or difference in speed?

avatar image jiteshvm · Apr 10, 2013 at 08:56 PM 0
Share

not sure about the performance. I think its just the na$$anonymous$$g convention

avatar image
9

Answer by Anxo · Oct 12, 2016 at 05:10 PM

I ran a performance test, 1000 cubes, one of them had the "Player" tag and ran the following code.

 public class FindPerformanceTask : MonoBehaviour {
 
     // Use this for initialization
     void RunTest () {
         System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
         stopWatch.Start();
         for (int i = 0; i < 1000000; i++) {
             GameObject player = GameObject.FindGameObjectWithTag("Player");
         }
         stopWatch.Stop();
 
         Debug.Log(stopWatch.ElapsedMilliseconds.ToString()+"ms");
     }
     void Update()
     {
         if(Input.GetKeyDown(KeyCode.Space)){
             RunTest();
         }
     }
     
 
 }

The Science is in! Both perform the same.

Comment
Add comment · Show 5 · 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 Bonfire-Boy · Oct 12, 2016 at 11:22 PM 1
Share

Although it's there and works, there doesn't appear to be such a function as GameObject.FindGameObjectWithTag in the API.

https://docs.unity3d.com/ScriptReference/GameObject.html

So, science notwithstanding, that suggests to me that one should prefer the documented FindWithTag.

But does anyone know what's going on here? $$anonymous$$aybe they changed the name and left the old one as an alias for backwards-compatibility or something like that?

avatar image LoungeKatt Bonfire-Boy · Nov 07, 2016 at 09:31 PM 0
Share

It is a well known fact the documentation on the site is often incomplete, inaccurate, or poorly written. The $$anonymous$$onoDevelop tooltips will at least verify usage parameters.

It is most likely the fact that "FindWithTag" has no logical plural ("FindsWithTag"?), but it would be rational to infer that FindObjects could reduce to FindObject.

API Reference

avatar image Bip901 · Jul 01, 2019 at 01:32 PM 1
Share

Interesting. I wonder why Unity made a duplicate function with no documentation. 6 years after this question was asked, and the function is still there.

avatar image kabakadam99 Bip901 · Dec 04, 2020 at 05:46 AM 0
Share

$$anonymous$$ake it 7 my friend. Welp, since there is no difference, I'll go with the shorter one.

avatar image Bip901 kabakadam99 · Dec 05, 2020 at 08:26 AM 0
Share

Yep. As noted by @Bonfire-Boy, the shorter one is also documented so it definitely should be used instead.

avatar image
-1

Answer by Dracorat · Apr 10, 2013 at 08:35 PM

GameObject.FindGameObjectsWithTag

Finds a list of objects.

The other finds only one and returns it.

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 jiteshvm · Apr 10, 2013 at 08:39 PM 0
Share

Yes. But there is also a function GameObject.FindGameObjectWithTag which only finds and returns one GameObject same as GameObject.FindWithTag

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

17 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

Related Questions

Distance thing with gameobject ? 4 Answers

How to get a list of gameobject tags in runtime 1 Answer

How to find one object in specific layer? 1 Answer

Swapping a tag for string not working, replacing a tag with a public string, help. 1 Answer

Destroying Multiple Objects with Tags 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