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 /
  • Help Room /
avatar image
0
Question by Jogabba · Mar 24, 2016 at 02:02 PM · findgameobjectswithtag

Can't find object by tag

Heya! I have a little doubt. I want to retrieve an instance of a Gameobject via its tag, but it doesn't work. The weird thing is that it works if I try to retrieve it by its name.

This is the code that does not work:

 public var Frog: GameObject[];
 
 function Start(){
     Frog =  GameObject.FindGameObjectsWithTag("Player");
 }

But this one does:

 public var Frog: GameObject;
 
 function Start(){
     Frog =  GameObject.Find("Frog(Clone)");
 }

Obviously I've made sure that the Frog gameobject has the Player tag. What am I missing? Any ideas?

Comment
Add comment · Show 1
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 msm437 · Jul 10, 2016 at 06:57 PM 0
Share

Same issue happened in my project with iOS, but it works well with android.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ReggieBeRetro · Jul 11, 2016 at 12:21 AM

This is what i use to find a tag to check i it dose in fact have a tag. I know its not what ur looking for but it might help for testing in C#.

if (Frog.gameObject.tag == "Player") { Debug.Log("Yup I Found IT!!!!"); } else { Debug.Log("No luck this time"); }

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
avatar image
0

Answer by IronKnigh · Jan 20, 2021 at 07:08 AM

Despite this being an issue from 2016, I've re-encountered it today in 2021. Basically, when you're instantiating an instance of a GameObject with tag "Player" in the Start() method and in another script you're trying to use GameObject.FindGameObjectWithTag("Player"); in it's Start() method, then the two happen simultaneously or out of order where the player instance hasn't spawned yet and you end up with a missing reference when your FindGameObjectWithTag() doesn't see the player object in the level at that point in time.

The fix is to do a quick reference check during Update, FixedUpdate, or any other method that occurs when the level has been fully loaded.

Also OP, it looks like you have a typo in your Frog = GameObject.~ line of code. You used the method that returns an array of objects instead of just one, FindGame*ObjectsWithTag() vs FindGameObject*WithTag().

I hope this helps!

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

53 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

Related Questions

How to use 2 tags in FindGameObjectsWithTag. 2 Answers

Check if transform.position matches position of any object in a given array 1 Answer

How to find all GameObjects with different tags excluding some tags. 0 Answers

I can't find child objects with using FindObjecstswtihTag, need help. 0 Answers

Find all GameObject or mesh tagged as "not walkable" on the navmesh 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