- Home /
How do I make gameobject invisible (2D)?
Let's say I have an empty gameobject with a ton of childed objects with images making up its graphics. Is there an easy way to disable rendering on a parent so it does the same for all of it's children (like a .enabled equivalent for rendering)? Or am I forced to reference each image component in the children manually and individually enable/disable each one?
Answer by bdubbert · Oct 28, 2021 at 10:13 PM
- You could just set the parent object to inactive - gameObject.SetActive(false);
 
- If you are using UI objects and a Canvas then disabling the canvas will cause all children UI objects to not render 
 
- If you do need to disable renderers one by one you don't need to reference each one, you can just do - foreach(Renderer r in GetComponentsInChildren<Renderer>()){r.enabled = false;}
 
- Deactivating the gameobject stops a lot more than just the rendering. It's stops all update calls too. Not what I'm looking for. 
- This worked for 2D, thanks. Only problem is you'd have to add a canvas to every 2D object you might want to make invisible. And of course this wouldn't work for 3D objects. I just thought toggling rendering would be universal on all gameobjects, 2D and 3D, just like active and enabled are. Surprised this isn't a thing in unity. 
- Yeah that's what I meant by manually. Trying to avoid getcomponent calls and dragging in references. 
Seems like toggling visibility of gameobject+children just isn't inherent in unity.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                