Skip to main content
added 1 character in body
Source Link
vonis22
  • 46
  • 1
  • 4

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 = ...;
   }
}

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.GetComponentsInChildren(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 = ...;
   }
}

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.GetComponentsInChildren<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 = ...;
   }
}
added 440 characters in body
Source Link
vonis22
  • 46
  • 1
  • 4

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.GetComponentsInChildren(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 = ...;
   }
}

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.

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.GetComponentsInChildren(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 = ...;
   }
}
deleted 79 characters in body
Source Link
House
  • 73.3k
  • 17
  • 185
  • 273

I suggest you take a look at this thread onSee the Unity Forum.

http://forum.unity3d.com/threads/get-all-the-childs-in-transform-even-if-the-childs-are-inactive.99452/#post-650888

Hope it helps.

EDITdocumentation for GetComponentsInChildren: Little bit of background info.

http://docs.unity3d.com/ScriptReference/GameObject.GetComponentsInChildren.htmlpublic Component[] GetComponentsInChildren(Type type, bool includeInactive = false);

This states you can use the boolean includeInactive behind GetComponentsInChildrenincludeInactive in GetComponentsInChildren to also get the inactive components. This way you can grab all the transforms. Even inactive ones.

I suggest you take a look at this thread on the Unity Forum.

http://forum.unity3d.com/threads/get-all-the-childs-in-transform-even-if-the-childs-are-inactive.99452/#post-650888

Hope it helps.

EDIT: Little bit of background info.

http://docs.unity3d.com/ScriptReference/GameObject.GetComponentsInChildren.html

This states you can use the boolean includeInactive behind GetComponentsInChildren to also get the inactive components. This way you can grab all the transforms. Even inactive ones.

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.

Source Link
vonis22
  • 46
  • 1
  • 4
Loading