Select your preferred scripting language. All code snippets will be displayed in this language.
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Closetype | The type of Component to retrieve. |
includeInactive | Should inactive Components be included in the found set? |
Returns all components of Type type
in the GameObject or any of its parents.
The search for components is carried out recursively on parent objects, so it includes parents of parents, and so on.
#pragma strict public class GetComponentsInParentExample extends MonoBehaviour { function Start() { var hingeJoints: Component[]; hingeJoints = GetComponentsInParent(HingeJoint); if (hingeJoints != null) { for (var joint: HingeJoint in hingeJoints) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects var hingesInactive: Component[] = GetComponentsInParent(HingeJoint, true); for (var joint: HingeJoint in hingesInactive) joint.useSpring = false; } } }
using UnityEngine;
public class GetComponentsInParentExample : MonoBehaviour { void Start() { Component[] hingeJoints;
hingeJoints = GetComponentsInParent(typeof(HingeJoint));
if (hingeJoints != null) { foreach (HingeJoint joint in hingeJoints) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects Component[] hingesInactive = GetComponentsInParent(typeof(HingeJoint), true);
foreach (HingeJoint joint in hingesInactive) joint.useSpring = false; } } }
includeInactive | Should inactive Components be included in the found set? |
Generic version. See the Generic Functions page for more details.
#pragma strict public class GetComponentsInParentExample extends MonoBehaviour { function Start() { var hingeJoints: HingeJoint[]; hingeJoints = GetComponentsInParent.<HingeJoint>(); if (hingeJoints != null) { for (var joint: HingeJoint in hingeJoints) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects var hingesInactive: HingeJoint[] = GetComponentsInParent.<HingeJoint>(true); for (var joint: HingeJoint in hingesInactive) joint.useSpring = false; } } }
using UnityEngine;
public class GetComponentsInParentExample : MonoBehaviour { void Start() { HingeJoint[] hingeJoints;
hingeJoints = GetComponentsInParent<HingeJoint>();
if (hingeJoints != null) { foreach (HingeJoint joint in hingeJoints) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects HingeJoint[] hingesInactive = GetComponentsInParent<HingeJoint>(true);
foreach (HingeJoint joint in hingesInactive) joint.useSpring = false; } } }
includeInactive | Should inactive Components be included in the found set? |
results | List holding the found Components. |
Find Components in GameObject or parents, and return them in List results
.
#pragma strict public class GetComponentsInParentExample extends MonoBehaviour { function Start() { var hingeJoints: List.<HingeJoint> = new List.<HingeJoint>(); GetComponentsInParent.<HingeJoint>(false, hingeJoints); if (hingeJoints != null) { for (var joint: HingeJoint in hingeJoints) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects var hingesInactive: List.<HingeJoint> = new List.<HingeJoint>(); GetComponentsInParent.<HingeJoint>(true, hingesInactive); for (var joint: HingeJoint in hingesInactive) joint.useSpring = false; } } }
using UnityEngine; using System.Collections.Generic;
public class GetComponentsInParentExample : MonoBehaviour { void Start() { List<HingeJoint> hingeJoints = new List<HingeJoint>();
GetComponentsInParent<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>();
GetComponentsInParent<HingeJoint>(true, hingesInactive);
foreach (HingeJoint joint in hingesInactive) joint.useSpring = false; } } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information