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
3
Question by joeyrubio · Feb 16, 2011 at 08:26 PM · gameobjectchildrenfindfindgameobjectswithtag

Is it possible to FindWithTag only within children of a certain gameObject?

In my game, certain objects my player interacts with have 4 empty spheres around them (all children of the object), which I've tagged as "Zone"s. Because there are many of these objects, it seems as I can't use FindGameObjectsWithTag to find an instance's 'Zones', because it will return ALL objects instances' zones. So I ask, is it possible to use this method within an instance of an object?

Returning all children of the object by looping through them is not a possible solution, as it has many other children with different tags.

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 JGeorge · Feb 16, 2011 at 08:36 PM 0
Share

What about the main objects, are those tagged or named the same?

avatar image joeyrubio · Feb 16, 2011 at 11:47 PM 0
Share

The main objects are tagged differently and also named differently. I got the answer I was looking for thanks to Jessy's answer!

1 Reply

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

Answer by Jessy · Feb 16, 2011 at 08:36 PM

No, you can't do what you're asking directly, but I don't see why looping is a problem.

foreach (Transform child in parentTransform) if (child.CompareTag("Zone")) {} 
// Put whatever you want in the brackets.

Why is that not appropriate?

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 joeyrubio · Feb 16, 2011 at 11:46 PM 0
Share

Awesome! CompareTag is exactly what I needed. I'll loop through all of them and the ones with the tag "Zone" are the ones I'll use to do what I want. Thank you very much!

avatar image Jessy · Feb 17, 2011 at 02:44 AM 0
Share

Certainly! ;-) There is another way to compare tags, but it's not as good thanks Eric! http://answers.unity3d.com/questions/34589/why-does-comparetag-exist

avatar image KarlKarl2000 · Dec 24, 2016 at 07:55 AM 0
Share

Jessy's answer is the best one I could find so far. I've updated it for my version of Unity 5.5.

"parentTransform" doesn't seem to work for me. Below is my hack.

 public Transform _myGameObject;
 
 void Awake()
 {
 
 //This finds the transform for the child gameobject 
 foreach (Transform child in transform) 
             if (child.CompareTag ("tagSomethingSomething")) {
                 _myGameObject = child;
             }
 }

Sharing is Carin' IndieNendoroid https://twitter.com/IndieNendoroid

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

1 Person is following this question.

avatar image

Related Questions

Find GameObject of tag "x" no matter where it is? 2 Answers

Better solution for GameObject.FindGameObjectsWithTag 2 Answers

Getcomponent error? 1 Answer

Best method to manage multiple tags 2 Answers

SetActiveRecursively not activating children 2 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