- Home /
C# Child GameObject Disabled Script SetActive(false)
I have a script that disables gameobjects parented to it. However when I re-enable the children their scripts are turned off. Any idea how I can fix this?
public List<GameObject> childrenList = new List<GameObject>();
void Start()
{
for(int i=0;i<childrenList.Count;i++)
if(childrenList[i] != null)
{
childrenList[i].gameObject.SetActive(false);
}
}
Answer by Andres-Fernandez · Aug 01, 2014 at 06:28 AM
If the parent is disabled, then the child will not execute its scripts. It can be active in hierarchy, but it needs the parent to be active to run its scripts.
Yes I know that. But the parent isn't disabled it's the children that are. After I re-enabled the child's script itself is still disabled.
Then you need to enable/disable the component itself. Check here.
Your answer
Follow this Question
Related Questions
C# Rotate GameObjects Regardless of List Size 2 Answers
Question on Using a Foreach Loop on Nested Children 1 Answer
C# Change Script Help 1 Answer
C# SetActive GameObject Array 2 Answers
C# GameObject Reverses Z Rotation 0 Answers