- Home /
How do I access the renderer from a child?
Hi.
Right now I have a parent GameObject with a model as the child. I have two scripts attached to the parent, one for movement and the other which accesses the renderer to switch materials in an array.
When I run the game it always comes back with script trying to access renderer but no renderer found on parent.
I've tried using GetComponentInChildren but I'm not sure if it should go in the Movement script or the renderer script, do my scripts need to reference the other?. I've also tried attaching the renderer script to the model but it still requires it for the parent.
What am I doing wrong?
Answer by psycocrusher · Oct 02, 2014 at 04:15 PM
You can go down on the hierarchy like this:
gameObject.Find("Parent/child/child/etc").renderer.enabled = false;
or
Directly access the child with:
transform.Find("ChildNameHere").renderer.enabled = false;
Thanks for the reply. Wouldn't your suggestion turn off the renderer? I need it to be still enabled when I switch the materials on the model.
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
List.Add component as Renderer, can't access? 1 Answer
Do something for each material in each renderer in children... 2 Answers
how do I change the properties of a material that are on the children of an object on script? 1 Answer
Disable multiple child components 1 Answer