Instantiate problem

Hi!

Ive got a problem…

I needed to instantiate a copy of gameObjects and after that in copy Destroy all inactive gameObject children, BUT as Instantiating makes all children active i cant do it…

Yes… I could Destroy original gameObjects inactive children, but i cant do it, because they are needed…

Can someone help me out - how to make sure, that children which are inactive in original gameObject will be Destroyed in copy of original gameObject keeping original gameObjects inactive children?

Function where part of it i have tried to do it until i realized that after Instantiating all children gameObject become active.

function SaveAvatar(p: GameObject)
{
	var copy: GameObject;
	copy=Instantiate(p);
	copy.name="SavedAvatar";
	copy.transform.parent=player.transform;
	copy.transform.position=Vector3.zero;

	for(var child2: Component in copy.GetComponentsInChildren(Component))
	{	
    	if(!child2.gameObject.active) Destroy(child2.gameObject);
	}
}

It seems that all prefabs are stores as inactive and upon instantiation their instances are set to active recursively, so you have to do this before/when making the prefab, it can’t be done at run-time. You could use tags or components to identify the children you want removed though.