type | The type of Component to retrieve. |
includeInactive | Should Components on inactive GameObjects be included in the found set? |
Returns all components of Type type
in the GameObject or any of its children.
The search for components is carried out recursively on child objects, so it includes children of children, and so on.
using UnityEngine;
public class GetComponentsInChildrenExample : MonoBehaviour { void Start( ) { Component[] hingeJoints;
hingeJoints = GetComponentsInChildren( typeof(HingeJoint) );
if( hingeJoints != null ) { foreach( HingeJoint joint in hingeJoints ) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects Component[] hingesInactive = GetComponentsInChildren( typeof(HingeJoint), true );
foreach( HingeJoint joint in hingesInactive ) joint.useSpring = false; } } }
includeInactive | Should inactive GameObjects be included in the found set? |
T[] A list of all found components matching the specified type.
Generic version. See the Generic Functions page for more details.
using UnityEngine;
public class GetComponentsInChildrenExample : MonoBehaviour { void Start( ) { HingeJoint[] hingeJoints;
hingeJoints = GetComponentsInChildren<HingeJoint>( );
if( hingeJoints != null ) { foreach( HingeJoint joint in hingeJoints ) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects HingeJoint[] hingesInactive = GetComponentsInChildren<HingeJoint>( true );
foreach( HingeJoint joint in hingesInactive ) joint.useSpring = false; } } }
results | List to receive found Components. |
includeInactive | Should inactive GameObjects be included in the found set? |
Return all found Components into List results
.
using UnityEngine; using System.Collections.Generic;
public class GetComponentsInChildrenExample : MonoBehaviour { void Start( ) { List<HingeJoint> hingeJoints = new List<HingeJoint>();
GetComponentsInChildren<HingeJoint>( false, hingeJoints );
if( hingeJoints != null ) { foreach( HingeJoint joint in hingeJoints ) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects List<HingeJoint> hingesInactive = new List<HingeJoint>();
GetComponentsInChildren<HingeJoint>( true, hingesInactive );
foreach( HingeJoint joint in hingesInactive ) joint.useSpring = false; } } }