How do I only deactivate all children in unity and leaving the parent active?
Method 1: Remove From Hierarchy Click on HubGuyPink and drag the GameObject to an empty space in the Hierarchy. Both parent and child will become independent GameObjects again. Easy peasy. Deleting the child GameObject will also make the parent GameObject independent.
foreach (Transform child in transform)
child.gameObject.SetActive(false);
//Assuming parent is the parent game object
for (int i = 0; i < parent.transform.childCount; i++)
{
var child = parent.transform.GetChild(i).gameObject;
if (child != null)
child.SetActive(false);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With