- Home /
Can a parent SetActive a child GameObject anymore
Hi all,
I am getting seriously frustrated with a simple feature of having two GameObjects that have a script with two functions that can be called that will turn on or off their respective child GameObject. Can this be done due to the changes in 4.0?
I have tried all sorts of different ways of getting access to the Child object and using SetActive but nothing works. The child GameObject never enables and sometimes it only enables in the Hierarchy and not in Scene!
Help! What am I doing wrong?
Thanks, Mark
Are the parents inActive? The old rules allowed active children with inactive parents, the new ones don't.
Answer by Mikilo · Feb 24, 2013 at 11:35 PM
Hello,
This may helps you:
for (int i = 0; i < this.transform.GetChildCount(); ++i)
{
this.transform.GetChild(i).gameObject.SetActive(true);
}
Didn't try the code above, but it should do what you asked.
Don't forget to leave your children active! When you disable the parent, all children are automatically 'disabled'... or rather not active and visible.
Answer by mwinteringham · Feb 25, 2013 at 02:28 PM
Turns out I was referencing the Prefab rather than the Instantiated object which was causing all the problems.
The above code however works a treat so happy to mark this as the Answer. Thanks for the help.
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
How to check parent value instead name value(more details in post) 3 Answers
Display Name Above Object 2 Answers
All encompassing Game Object. 1 Answer