Getting parent from a child to getting all children

I have a script on a child object. I can get access to the parent like this

parentGO = this.transform.parent.gameObject;

This doesn’t really do anything for me though, from this child script I need to get all the colliders in the parent and children and turn isTrigger true.
Is it possible to do this?
Thanks
Matt

1 Like

Once you have the parent, you can use GetComponentsInChildren() to get all colliders (returns an array of Colliders).

Then iterate that array and set .isTrigger to true!

Right but how do I get the colliders if the parent is a gameObject, also the parent is not an array.

private GameObject parentGO ;
private GameObject[ ] allChildern;
void Start()
{
parentGO = transform.root; // gets the highest parent object
allChildern = parentGO.GetComponentsInChildren();

//then a for loop to do something with each child
for(int i = 0; i < allChildern.Length; i++)
{
allChildern*.something…code*
}
}

Thanks for your help, that second line in Start() is what was killing me, I couldn’t figure out how to do that.