See the documentation for GetComponentsInChildren
:
public Component[] GetComponentsInChildren(Type type, bool includeInactive = false);
This states you can use the boolean includeInactive
in GetComponentsInChildren
to also get the inactive components. This way you can grab all the transforms. Even inactive ones. So you would probably want to do this:
//Create an array of SpriteRenderers
SpriteRenderer[] _spriteRenderers;
void Start ()
{
_spriteRenderers = transform.GetComponentsInChildrenGetComponentsInChildren<SpriteRenderer>(SpriteRenderer,true); //This returns an Array
//Change the material on all the Sprite Renderers.
for (int i = 0; i < _spriteRenderers.Length; i++)
{
_spriteRenderers[i].material = ...;
}
}