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 /
avatar image
0
Question by B_Dombro · May 02, 2016 at 08:31 PM · scripting problemerrorerror messagescriptingbasicssyntax error

Was gameObject.GetChild(childsName); a thing?

In my project I am going through old code converting our networking solution from Tnet to Photon. Up until just now these lines did not throw an error and worked.

 login = displayInst.gameObject.GetChild("LoginScreen");
 normal = displayInst.gameObject.GetChild("NormalScreen");

After making my networking changes I started getting an error saying :

Type UnityEngine.GameObject' does not contain a definition for GetChild' and no extension method GetChild of type UnityEngine.GameObject could be found (are you missing a using directive or an assembly reference?)

I have not made any changes to those lines. After some research all I'm seeing the closest thing could be gameObject.Transform.GetChild(index);

Opened the script on another computer without any of the networking changes and MonoDevelop would still AutoComplete gameObject.GetChild(string);

Clearly it's not a thing now, but was it maybe a few updates ago? Why would my script compile and run just fine before making our networking changes? Working around the issue but still very confused as to what is going on....

attached a screenshot just to prove it

alt text

mysterios.png (19.2 kB)
Comment
Add comment · Show 3
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 Scribe · May 02, 2016 at 09:15 PM 0
Share

Are you sure you haven't deleted some extension method of your own? I have no recollection of this function, and at least checking back to 4.0 documentation doesn't seem to turn anything up. For the same functionality (using a string) you can use Transform.Find(someString) to find children by string.

avatar image B_Dombro Scribe · May 03, 2016 at 06:05 PM 0
Share

Went back and double checked apparently Tnet wrote an override method for gameObject. As soon as I added the namespace back it worked. strange

avatar image meat5000 ♦ · May 03, 2016 at 11:18 AM 0
Share

Parenting structure is actually handled by the Transform. As every gameobject has a Transform this is not a problem.

GameObject.Find searches the Root and all its children (so, every gameobject) and Transform.Find will search only the children of that one object. GetChild is also a Transform $$anonymous$$ethod as well as other useful $$anonymous$$ethods.

2 Replies

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

Answer by B_Dombro · May 03, 2016 at 06:24 PM

Turns out gameObject.GetChild("object name"); is a valid method when using the Tnet namespace.

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
1

Answer by Dave-Carlile · May 03, 2016 at 12:18 PM

Doing a quick Google search for Unity3D "GameObject.GetChild" yielded up this on the Unity wiki...

http://wiki.unity3d.com/index.php/VWheelCollider

About 60% of the way down you'll find...

 public static class ClassExtensions
 {
     // GameObject
     public static GameObject GetChild(this GameObject obj, string name) { return obj.transform.FindChild(name) ? obj.transform.FindChild(name).gameObject : null; }


Which creates a GameObject extension. This is probably what your old project had in it somewhere, or some equivalent extension. It's possible that it got blown away by something when you made your changes.

I don't think you need the FindChild thing anymore, in fact that may be deprecated, or at least there were some changes around those find functions awhile back - don't recall the details.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I fix this problem-it won't let me start my game in Unity because of an override problem 1 Answer

How do I inherit certain varibles and functions from another script. 1 Answer

Error "OnTriggerEnter: this message has to be of type: Collider" 0 Answers

Script Error 1 Answer

error CS0117: `UnityEngine.Graphics' does not contain a definition for `DrawProceduralIndirectNow' 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