Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Object invisible

Discussion in 'Editor & General Support' started by htwarrior, Mar 17, 2006.

  1. htwarrior

    htwarrior

    Joined:
    Feb 25, 2006
    Posts:
    40
    How do I make an objet invisible ? There are some objects that I want to make visible sometimes and sometimes not.

    HTwarrior
     
  2. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Yes a good one! I looked it up after reading your post because I want my objects to flicker when they are hit (arcade style). It seems the mesh renderer does not take a show/hide parameter, and add/remove the mesh render component by scripting seems like a bad idea, performance wise.
    Anyone? :roll:
     
  3. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    Strangely, 'renderer.active = false' doesn't seem to actually hide the object. Instead, it seems to deactivate the whole object and causes scripts to break. It'd be more useful if it did hide the object, or if there were some other property for controlling visibility.

    I've been making objects disappear by moving them far out of the camera view (either behind the camera, or simply anywhere beyond the camera's far plane). That's great for things with no rigid body, but it's likely to mess up the simulation for objects which have one.

    Here's another off-the-wall idea: maybe it's possible to hide an object by changing its material to one which uses a shader that causes the object to not be drawn. Not just to make it totally transparent, which is inefficient, but to stop it from being drawn altogether. Just a thought.
     
  4. htwarrior

    htwarrior

    Joined:
    Feb 25, 2006
    Posts:
    40
    I think I will put my object far away from the camera view. Thanks
    Htwarrior
     
  5. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    Well the best way to make a object invisible (i think) is to just change it to a layer that the camera is not seeing. You certainly dont break script that way.

    Bill
     
  6. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    Good point. I'm glad someone's awake, because I'm obviously not. ;)
     
  7. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    You type while asleep!? Neil I knew you had many talents but _thats_ impressive.

    Bill
     
  8. madcalf

    madcalf

    Joined:
    Jan 12, 2006
    Posts:
    56
    How exactly could you do this? Can it be done with scripting? I'm trying to make an object that can be toggled visible/invisible based on the game state. Is there a way I can simply move it to an "invisibles" layer when it's invisible and then move it back to it's original layer when it's visible?

    thanx!
    d
     
  9. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    You just have to set the GameObject's layer property to the number of the layer you want it to be in:

    Code (csharp):
    1. gameObject.layer = 9;
    Look in Edit->Project Settings->Tags to figure out which number to use for each layer.
     
  10. madcalf

    madcalf

    Joined:
    Jan 12, 2006
    Posts:
    56
    Thanx! This did the trick. Nice idea to switch between a layer that the camera doesn't see.
     
  11. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,271
    I have to dig up this thread to ask if there's a way to make an object invisible in the editor as well. I have a large controller object that kind of gets in the way when I want to see things (but it needs to be there). Any suggestions?
     
  12. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    In Unity 1.5, the scene view has the layers popup - by default all layers are visible. But you can turn any of them off.
     
  13. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    For making an object become invisible, you can just disable the renderer.

    from scripting: renderer.enabled = false;

    This will only change the object's visibility. It will still get update calls etc...
     
  14. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,271
    Great. Thanks guys.