Instancing Complex Prefabs to a Specific Layer

I want to instantiate a complex object (i.e. many child objects off the root transform) and have all objects in the instance on the same layer.

The normal behavior in Unity appears to be that instances are assigned to the Default layer, even when instanced inside a GO that is on another layer.

Anyone know of a quick and easy way to accomplish this?

Try this:

var wantedLayer = 1;

function Start ()
{
	var children = GetComponentsInChildren (Transform);
	for (var child in children)
		t.gameObject.layer = wantedLayer;
}

Thanks!

Here’s a function I wrote based on your code (fixed your typo) that does the trick:

function AssignLayerDeep (theInstance, theLayer) {

  var children = theInstance.GetComponentsInChildren (Transform); 
  
  for (var t : Transform in children) t.gameObject.layer = theLayer; 

}