Gizmos are drawn to all cameras

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:

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:

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?

2 Likes

Can anyone add anything to this thread?

Just bumping this.

A flag on cameras to optionally disable Gizmos from being drawn by that camera would be great.

1 Like

Agreed!

Here’s a way to get around this limitation:

	void OnDrawGizmos() {
		if ((Camera.current.cullingMask  (1 << gameObject.layer)) > 0) {
			// Do your stuff here
		}
	}

It’s annoying that you have to do this in each class, but hopefully they will fix this soon.

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)

if (Camera.current != LocalPlayerManager.p.localCamera)

Is there any news/ a better solution to this? Still now way to hide builtin gizmos?

I just put this in the start of my OnDrawGizmos method:

if (Camera.current != Camera.main)
        {
            return;
        }
2 Likes

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.

Almost 10 years later, and this would still be nice…

3 Likes

Bump, need to be able to disable gizmos on a camera as well.

1 Like

Bump…

1 Like

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.