Search Unity

how to make my 3D Gameobject invisible if no renderer attached ?

Discussion in 'General Graphics' started by arvrappps, May 21, 2017.

  1. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
    I have 3D object and I want to make it invisible by turning off its rendering. But when I run the code in runtime it shows ::
    " Exception in callback: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> UnityEngine.MissingComponentException: There is no 'Renderer' attached to the "3dObject" game object, but a script is trying to access it."
    I want to know if There is no renderer then how I am able to see that object in scene/game view. and also in inspector nothing is there (mesh renderer / renderer / mesh filter).
    I'm Using c# : this.GetComponent().enabled=true;
    I'm new in unity and I know its a pretty basic question but not getting anything. Need Help..

     
  2. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Are you sure that the GameObject doesn't have a child, parent or sibling that has a Mesh or Skinned Mesh Renderer?
     
    arvrappps likes this.
  3. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    247
  4. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
    sorry ..in this model there is a long child list and one of them is having skinned mesh renderer.
    Now my doubts are clear. but one thing, how to access all the renderers present on child of that particular 3D Model .. I'm using :: Renderer[] ren = this.GetComponentsInChildren<Renderer>();
     
    Last edited: May 22, 2017
  5. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    247
    Every object has a tick that controls its Enabled state. But if you use the func above on the parent, then all children will become disabled automatically. The children in the inspector will show they are active but that's only local state. Meaning you might disable an object there and when you reenable the parent , that object will remain inactive. But since the parent is disabled then the global state of all children will be disabled.