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 Hamesh81 · Nov 02, 2014 at 08:29 AM · transformchildfindontriggerstay

How can I find a specific child transform of the object in the trigger?

I have a trigger with the script below. When a player is in the trigger I would like to search through their hierarchy for a specific bone (mainHandName) and assign its transform as the variable mainHandTransform. I am using the standard 3rd person Controller for the testing, but for some reason this isn't working. I can see when the player is in the trigger because the boolean is set to true, but the transform variable is not being assigned. Where am I going wrong?

     public string mainHandName = "Bip001 R Hand";
     public Transform mainHandTransform;
     public bool inTrigger = false;
     
     void OnTriggerStay(Collider other) {
             if (other.collider.tag == "Player") {
                 inTrigger = true;
                 mainHandTransform = other.transform.Find(mainHandName);
             }    
         }
 }
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 tanoshimi · Nov 02, 2014 at 08:58 AM 0
Share

Is that really your code? Your first line is missing quote marks around the string:

 public string mainHandName = "Bip001 R Hand";

I'd also try FindChild rather than Find:

 mainHandTransform = other.transform.FindChild(mainHandName);
avatar image Hamesh81 · Nov 02, 2014 at 09:11 AM 0
Share

Sorry for the error I copied it too quickly, in my actual code I assign it through the inspector. I have tried using FindChild ins$$anonymous$$d of Find as you suggested but it still isn't working. I have used transform.Find previously to locate transforms in the hierarchy, but I have never used transform.FindChild before. I can't find any documentation on FindChild, how different is it to regular Find?

1 Reply

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

Answer by Hamesh81 · Nov 02, 2014 at 10:57 AM

I finally worked it out! So apparently transform.Find only searches through the immediate children. Therefore in order to search through the entire bone hierarchy for a specific child/grandchild/great grandchild etc you need to first use getcomponentsinchildren and then use a foreach loop to search for the specific bone by name. I think transform.Find would be much more useful if you could actually use it for more than just the immediate child; needing to specify the entire path to get to it doesn't make it easier than a foreach loop.

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

26 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

Related Questions

transform.Find(string)? 2 Answers

Why GameObject.Find() work and parent.transform.Find() doesn't work? 1 Answer

FindChild not working? (Pick up Object) 2 Answers

Finding Children question 3 Answers

about transform find 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