- Home /
Children Mesh Render Issues.
I am attempting to turn off all of the child objects SkinnedMeshRenderers and I am using his script:
var theObject : GameObject;
function Update ()
{
theObject.GetComponentsInChildren.<SkinnedMeshRenderer>().enabled = false;
}
However I am receiving this error on run-time:
MissingFieldException: UnityEngine.SkinnedMeshRenderer[].enabled
Would I have to call the individual renderers, or is enabled not used for renderers?
Answer by Cherno · Nov 08, 2015 at 11:36 PM
Yes, you have to iterate through all the components and set each one's active state seperately. You can't use .enabled (or similar variables) with an array of objects.
Chemo is right. Also, I would add that doing that each update might not be a good idea in general.
Well that kinda sucks, so if you have several objects, with each object having various child renderers you would have to call each and every one? What is the point of "GetComponentsInChildren" then?
The point of GetComponentsInChildren is, as the function name says, get all the components in the object's children :D Since each component can have different values (active state etc.), it's not possible or even reasonable to treat them like one conglomerate.
Your answer
Follow this Question
Related Questions
Changing the materials in Editor Mode Without Getting the leak Error 3 Answers
Monodevelop not starting 1 Answer
Unity 4.0.0f7 GetThreadContext failed 2 Answers
Setting materials at runtime 1 Answer
Spawn Script Issue 0 Answers