Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

GetComponentsInChildren bugged?

Discussion in 'Scripting' started by JovanD, Feb 26, 2015.

  1. JovanD

    JovanD

    Joined:
    Jan 5, 2014
    Posts:
    206
    When i use " GetComponentsInChildren < Transform > ();" it also adds parent's transform to that array, is this a bug or intended behaviour? Also how can i only get and set transform in children and not parent?
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,153
    JovanD likes this.
  3. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,503
    Code (csharp):
    1.  
    2. Transform[] children = GetComponentsInChildren<Transform>().Where(t => t != transform).ToArray();
    3.  
     
unityunity