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
0
Question by Highwalker · Jun 13, 2015 at 11:43 PM · errorbugstartstrange

FindGameObjectWithTag () failing in unity 5.0.2?

It seems as if since upgrading to unity 5.0.2, this method will randomly fail. My project could be working fine the day before, but then it just poops out the next day, with the only difference being that my computer was turned off. And the weirdest part, is that I can that method several times in several classes. And they all work, except when trying to find one specific object. And yes, I did check if my tags somehow got messed up, and they're all fine. Has anyone encountered something similar? Or know what could be causing this? Is there maybe some setting or an override method, which will ensure that the object which fails is loaded before any other?

Thank you

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 Guppie1337 · Jun 14, 2015 at 12:21 PM 0
Share

Are you referring to GameObject.FindWithTag()?

avatar image Highwalker · Jun 16, 2015 at 03:21 AM 0
Share

I use GameObject.FindGameObjectWithTag (). GameObject.FindWithTag () threw me some errors when the unity script updater changed some FindGameObjectWithTag methods to FindWithTag. So I always stuck to FindGameObjectWithTag.

1 Reply

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

Answer by Guppie1337 · Jun 16, 2015 at 05:08 AM

You basically have 2 options here:

1) You can use GameObject.FindWithTag() which will return 1 result based off the GameObject that has the tag.

 public GameObject myGameObject;
 
 void Start ()
 {
   //Single result. 1 GameObject.
   myGameObject = GameObject.FindWithTag("");
 
   //Do something with the GameObject.
   Instantiate (myGameObject, whateverVector, whateverRotation);
 }

2) GameObject.FindGameObjectsWithTag() constructs an array of GameObjects that share the same tag (which I believe you are using). To call a GameObject with this 2nd method you would need to call for it by index.

 //This requires array brackets.
 public GameObject[] myGameObject;
 
 void Start ()
 {
   //Wrong way to call it. Remember, it's an array.
   myGameObject = GameObject.FindGameObjectsWithTag("");
 
   //Adding brackets allows index to fill appropriately.
   myGameObject[] = GameObject.FindGameObjectsWithTag("");
 
   //You can also explicitly declare a single index.
   myGameObject[0] = GameObject.FindWithTag("");
 }

Not that the 2nd one isn't actually incorrect, but the result depends on how it fits into the code.

If you do choose to use the second method to do the job, remember it needs the index and brackets.

 Instantiate (myGameObject[0], whateverVector, whateverRotation);

Comment
Add comment · Show 3 · 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 Guppie1337 · Jun 16, 2015 at 05:28 AM 0
Share

Also note, these are ways to FIND your GameObjects. You can of course assign GameObjects in a different number of ways

avatar image Highwalker · Jun 16, 2015 at 06:01 AM 0
Share

Hmmm... interesting. I am not using FindGameObjectsWithTag. But am using FindGameObjectWithTag. I wanted to find it in the api, to post it here, but they seem to have removed it. I'm guessing they changed it to FindWithTag with unity 5.0. I'm not sure why FindWithTag was throwing me errors before. Nor do I understand why FindGameObjectWithTag still works 99% of the time. I guess tomorrow I'll see what happens if I replace all of them with FindWithTag. Thanks bro, you definitely seemed to have pointed me to the right direction :)

avatar image Guppie1337 · Jun 16, 2015 at 06:06 AM 0
Share

You're welcome. If this helped you, please make sure to tick the answer and pay it forward. :) Let me know if you need anything else.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity 5 fatal error 3 Answers

GetThreadContext failed (Unity 5) 0 Answers

Why is Unity always adding some strange Transformations? 0 Answers

Strange physics, rigidbody, iTween activity 1 Answer

press play, game objects get deleted, game breaks. 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