Search Unity

GetComponentsInChildren bugged?

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

  1. JovanD

    JovanD

    Joined:
    Jan 5, 2014
    Posts:
    205
    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,190
    JovanD likes this.
  3. KelsoMRK

    KelsoMRK

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