Disabling GameObject's children

I want to disabled all gameobjects contained in a gameobject, but it doesn’t work with this :

	var children : GameObject[] = gameObject.GetComponents(typeof(GameObject));
	for (var child : GameObject in children) 
	{
		child.active = false;
	}

I’ve got this error :
“InvalidCastException: Cannot cast from source type to destination type.”

Is the method wrong ?

http://unity3d.com/support/documentation/ScriptReference/GameObject.SetActiveRecursively.html

thanks :slight_smile:

Uh, when a game object is disabled, it’s not possible to find it with gameObject.Find(“objectname”) ?

I usually disable the renderers instead of the gameobject - so then you can still find it

I’ve found a solution. I copy the reference of the gameobject in a private variable to reuse later.