Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Where is transform.FindChild() ???

Discussion in 'Scripting' started by kenshin, Apr 26, 2012.

  1. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    Hi there!

    I have updated unity3d to 3.5.1f2 and I found a strange situation with documentation:
    I can't find anywhere gameobject transform.FindChild methode documentation.

    ...but in my code I am using this and all works fine.

    Is this methode deprecated? or is just a little error in documentation files?

    Kenshin
     
  2. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    There are many "hidden" methods in Unity, and I often wonder if it's because they're deprecated or Unity just forgot to place them in the docs (or they're considered "internal", while not really being internal). Would really like to get an answer too :)
     
  3. MADmarine

    MADmarine

    Joined:
    Aug 31, 2010
    Posts:
    627
    I'm guessing it's depreciated yeah, as Find and FindChild do the same thing.
     
  4. shawn

    shawn

    Unity Technologies

    Joined:
    Aug 4, 2007
    Posts:
    552
    Usually when there's public API that's undocumented it means that it is API that isn't ready to be officially supported. Sometimes it means that it just fell through the cracks. Or it can mean something else entirely. Regardless of the why it is public and undocumented be aware when any API is not documented it is not supported and may change or be removed at anytime in the future.
     
  5. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    But, how is that different than any other API?
     
  6. shawn

    shawn

    Unity Technologies

    Joined:
    Aug 4, 2007
    Posts:
    552
    It's most apparent with the webplayer. With the webplayer Unity plays old content with new players, so Unity needs to keep a backwards compatible API. If you use API that officially supported then you can rest assured that new webplayer versions will be able to play the content that you deployed with an older version of Unity. And when Unity does eventually break backwards compatibility, then multiple versions of the webplayer runtime will live side by side in the webplayer plugin, so that old content can still be played.

    If you use API that is not officially supported then that API may not remain consistent with newer versions of the webplayer, which means that your old content may break with these newer webplayers.
     
  7. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    Really?

    I was wondering that FindChild() is more efficient than Find() if you know that you can search only starting from a specific gameobject.

    I understand, thanks for your explanation.
    But my question now is:
    ...is or is not a good idea to use FindChild() in my code? :)

    Does exist another way to search gameobject that are childs of another gameobject?
     
  8. shawn

    shawn

    Unity Technologies

    Joined:
    Aug 4, 2007
    Posts:
    552
    Transform.Find and Transform.FindChild are identical.

    This is the implementation of FindChild:
    Code (csharp):
    1. public Transform FindChild (string name) { return Find(name); }
    So use Find, since it is officially documented.
     
    Harinezumi likes this.
  9. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    Ok, now is clear.
    Thanks!