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 /
This question was closed Oct 08, 2013 at 01:30 AM by DeadKenny for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DeadKenny · Oct 08, 2013 at 12:02 AM · transformchildweaponfindpickup

FindChild not working? (Pick up Object)

I cannot get this child of an object to become the transform weaponHandle in this code, it just makes it empty.

What this code is supposed to do is pick up a weapon and drop the one already in the hand. It works but there is a problem with the weaponHandle, which is not being found and then becomes null.

It is using a raycast to hit the gun and then do the rest.

code:

 if(Physics.Raycast(aimray, out aimhit)){
             
 
             if(aimhit.transform.tag == "weapon"){
                 
                 if(Input.GetKeyDown(KeyCode.Q)){
                         
                        
                         aimhit.transform.parent = handR;
                         aimhit.transform.position = handR.position;
                         weaponExtraHandle = aimhit.transform.FindChild("extrahandle");                       
                     
                         Destroy(aimhit.transform.rigidbody);
                     
                         weapon01.GetComponent<Rifle>().enabled = false;
                         weapon01.transform.parent = null;                
                         weapon01.AddComponent<Rigidbody>();
                     
                     
                         weapon01 = aimhit.transform.gameObject;            
                         
                         
                     
                 }
                 

Please help.

My game WIP: http://forum.unity3d.com/threads/200629-Omega-Void-WIP

Comment
Add comment · Show 5
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 clunk47 · Oct 08, 2013 at 12:14 AM 0
Share

Please post the full code, just edit the question with it all added and I'll be happy to throw it in Unity and troubleshoot for you :)

avatar image DeadKenny · Oct 08, 2013 at 12:33 AM 0
Share

Holy crap its a massive code with other codes attached to it. Is there nothing you can tell me from this?

Its the weaponHandle FindCHild which is not finding the child in the object the transform hits.

It recognises the hit and parents the gun, drops the held one etc. Only the weaponHandle is not being found.

avatar image DeadKenny · Oct 08, 2013 at 12:50 AM 0
Share

Everything is named correctly too.

avatar image clunk47 · Oct 08, 2013 at 12:55 AM 2
Share

Well with the little info you provided, all I can tell you to have a look at Transform.Find("Name of Object you wish to find"). You'll notice if you refer to the Script Ref, like $$anonymous$$eat5k says, FindChild is not in the docs.

avatar image DeadKenny · Oct 08, 2013 at 01:28 AM 0
Share

FindChild works though, but I have no idea what the difference between Find and FindChild could be.

Either way I fixed it. I put the answer below.

2 Replies

  • Sort: 
avatar image
4
Best Answer

Answer by DeadKenny · Oct 08, 2013 at 01:26 AM

I had to directly reference the location of the child in the

  weaponExtraHandle = aimhit.transform.Find("connectBarrelBone/barrel/handle");
 
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 meat5000 ♦ · Oct 08, 2013 at 01:28 AM 1
Share

Accept your own answer and +1 to comments/answers that helped :)

  • for showing a commonly unknown way to use transform.Find

avatar image DeadKenny · Oct 08, 2013 at 01:31 AM 0
Share

$$anonymous$$y first answer, makes me feel less dumb lol.

avatar image clunk47 · Oct 08, 2013 at 01:54 AM 0
Share
  • for posting resolution and upvoting helpful comments / answers.

avatar image
2

Answer by meat5000 · Oct 08, 2013 at 12:58 AM

I don't see FindChild in the docs.

It's transform.Find("ChildObjectName") or transform.GetChild(intIndex)

Comment
Add comment · Show 4 · 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 clunk47 · Oct 08, 2013 at 01:08 AM 0
Share
  • for legit refs :D

avatar image DeadKenny · Oct 08, 2013 at 01:10 AM 0
Share

Find and FindChild seem to do the exact same thing. It makes no difference.

avatar image meat5000 ♦ · Oct 08, 2013 at 01:13 AM 1
Share

Does aimhit have a child object?

Does object extrahandle actually have a space or caps in the name?

avatar image DeadKenny · Oct 08, 2013 at 01:22 AM 0
Share

Oh my god ok solved it.

I had to directly reference the location of the child in the

 transform.Find("connectBarrelBone/barrel/handle");
 
 

I had tried it before but like a complete dipS!@t I kept missing /barrel/ part.

Anyway. Thanks for feedback.

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

transform.Find(string)? 2 Answers

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

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

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