Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

GetComponents/InParent/InChildren list overload not documented

Discussion in 'Documentation' started by Baste, Nov 1, 2016.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,352
    GetComponents and GetComponentsInChildren and GetComponentsInParent have these overloads available:

    Code (csharp):
    1. public void GetComponentsInParent<T>(bool includeInactive, List<T> results);
    2. public void GetComponentsInChildren<T>(bool includeInactive, List<T> result);
    3. public void GetComponents<T>(List<T> results);
    4.  
    5. //also this one, for when you hate writing good code:
    6. public void GetComponents(Type type, List<Component> results);
    None of these methods are mentioned anywhere in the docs.

    Doing a quick check, it seems like the methods clear the provided list, and then put the results in it. It seems like this is meant as a gc-free alternative to GetComponents (yay!). Using a List<T> instead of an array with an int return that defines the count of elements also makes this a much better solution to the gc problem than eg. Physics.RaycastAll and NavMeshPath.GetCornersNonAlloc!

    It'd be nice to have clear docs on what the method does, though!
     
    efge and landon912 like this.
  2. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,288
    Added into the doc team list of work to do. It's common for functions to have overload versions which need documentation. :-(

    (Thanks for all the comments and observations btw.)
     
  3. tsomda

    tsomda

    Joined:
    Mar 15, 2017
    Posts:
    1
    It seems like it is not on the documentation yet. :(

    One of these overloads is really helpful to me!
    It makes the code much cleaner.

    not very clean:
    myScriptList= new List<MyScript>(GetComponents<MyScript>());

    much cleaner:
    GetComponents<MyScript>(myScriptList);

    :)
     
  4. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    96
    I believe this is still yet to be done...