Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Gizmos are drawn to all cameras

Discussion in 'Editor & General Support' started by andymads, Jan 2, 2012.

  1. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    It seems as if gizmos are drawn to all cameras with OnDrawGizmos being called for each camera. This is not a big deal unless you have a camera with a non-default Normalized View Port Rect. So using an example with 2 cameras, what you get is this:

    $gizmos1.jpg

    I was unable to find a built-in solution, so what I did was use a flag in my OnDrawGizmos method that was set/cleared by OnPreRender/OnPostRender methods on a script attached to my cameras.

    Giving this:

    $gizmos2.jpg

    However, the built-in Label Icons are still drawn to both cameras and I can't see a way around this. And, I really want to use these labels as they are very useful.

    Do Unity Cameras need a Gizmos toggle?
     
    unity_iogames and KpyaccaH like this.
  2. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Can anyone add anything to this thread?
     
  3. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Just bumping this.
     
  4. kevork

    kevork

    Joined:
    Aug 28, 2011
    Posts:
    31
    A flag on cameras to optionally disable Gizmos from being drawn by that camera would be great.
     
    KpyaccaH likes this.
  5. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Agreed!
     
  6. glennpow

    glennpow

    Joined:
    Jan 30, 2012
    Posts:
    56
    Here's a way to get around this limitation:

    Code (csharp):
    1.     void OnDrawGizmos() {
    2.         if ((Camera.current.cullingMask  (1 << gameObject.layer)) > 0) {
    3.             // Do your stuff here
    4.         }
    5.     }
    6.  
    It's annoying that you have to do this in each class, but hopefully they will fix this soon.
     
  7. RKSandswept

    RKSandswept

    Joined:
    Apr 26, 2013
    Posts:
    22
    My implementation of the previously suggested solution is as follows (I cache the camera references so I don't have to get them by name)
    (and we have a First person arms camera, a weather camera, and a main camera, some of which have different field of view)

    Code (csharp):
    1. if (Camera.current != LocalPlayerManager.p.localCamera)
     
  8. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    374
    Is there any news/ a better solution to this? Still now way to hide builtin gizmos?
     
  9. PixxlMan

    PixxlMan

    Joined:
    Dec 19, 2018
    Posts:
    1
    I just put this in the start of my OnDrawGizmos method:

    Code (CSharp):
    1. if (Camera.current != Camera.main)
    2.         {
    3.             return;
    4.         }
     
    tokar_dev and TwoBitMachines like this.
  10. GarlicDipping

    GarlicDipping

    Joined:
    Sep 7, 2013
    Posts:
    33
    Any update on this? Still, game view cannot select which cameras to draw gizmos.

    For current workaround, I had to move UI Camera from (0,0,0) to (1000, 1000, 0) but it's too dumb solution. I dont' want to implement OnDrawGizmos on EVERY debug script I make.
     
  11. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    628
    Almost 10 years later, and this would still be nice...
     
  12. madGlory

    madGlory

    Joined:
    Jan 12, 2016
    Posts:
    44
    Bump, need to be able to disable gizmos on a camera as well.
     
    s4shrish likes this.
  13. Deceleris

    Deceleris

    Joined:
    Jan 3, 2018
    Posts:
    21
    Bump...
     
    bluescrn likes this.
  14. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    628
    A solution for this with UI cameras is better layer management. Gizmos won't be drawn for objects that aren't rendered by the camera.

    You can use Tools.visibleLayers to hide layers (particularly the UI layer!) from the scene view. So I've now got a ToolbarExtender button to toggle this, and made sure that all gizmo-drawing UI components are now in the UI layer.

    This makes it much easier to select scene objects for debugging in cases where most clicks in the scene window were usually selecting a great big UI canvas.