- Home /
Disabling child objects with their own child objects
Hello,
I have searched everywhere and cannot find a way to disable a child object without it being deleted forever. What I'm looking for is the javascript to simply disable the child from the parent script without completely deleting the child object.
Thanks in advance
How are you accessing the child? How do you know it is being deleted? Disabled objects cannot be found by common finding routines like GameObject.FindGameObjectsWithTag().
Answer by Lachee1 · Apr 13, 2014 at 07:50 AM
The following script will deactivate each child of a transform. This code has not been tested, but it should work non-the-less
Reference: http://docs.unity3d.com/Documentation/ScriptReference/Transform.html
C# Version:
foreach(Transform child in transform){
//Add a condition statement here to only deactivate the correct children
child.gameObject.SetActive(false);
}
JScript Version:
for(var child : Transform in transform){
//Add a condition statement here to only deactivate the correct children
child.gameObject.SetActive(false);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613142603im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Make a simple tree 1 Answer
Target child of child without knowing name? 1 Answer
Child of Parent 1 Answer
Calling a function of another object's child? 1 Answer
Pick up toy and attach to hand 1 Answer