Last active
June 2, 2022 10:31
-
-
Save unitycoder/f7ed03311b328fdbf1d5 to your computer and use it in GitHub Desktop.
Loop All Transform Children (not deep scan)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// loops only first level | |
foreach (Transform child in transform) | |
{ | |
Debug.Log(child.name); | |
} | |
// loop all recursive https://forum.unity.com/threads/loop-through-all-children.53473/#post-340519 | |
void TraverseHierarchy(Transform root) | |
{ | |
for (Transform child in root) { | |
TraverseHierarchy(child); | |
} | |
} | |
// Best, loop all with getcomponentsinchildren http://answers.unity.com/answers/287672/view.html | |
Transform[] Children = GetComponentsInChildren<Transform>(includeInactive:true); | |
foreach (Transform child in Children) { | |
// whatever | |
} | |
// activate all parents starting from child | |
Transform rootParent = someChildTransform; | |
while (rootParent != null) | |
{ | |
rootParent.gameObject.SetActive(true); | |
rootParent = rootParent.parent; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment