- Home /
Draw Gizmos without Depth-test
I need to draw my gizmos without using a depth test. I'm trying to replicate the way bones work and are selected within Maya, where each joint has a spherical gizmo and draws a line towards their child joints. My goal is have our animators able to work directly within Unity without having to use the hierarchy to select joints.
Less the left, more the right:
It looks like Gizmos actually did this pre-3.5:
Gizmos are now depth-tested, and exist in world space. The gizmo size can be adjusted using the existing gizmos size slider.
It's more complicated to use, but you might check out the UnityEditor's Handles class.
Edit: Tried that, found a workaround using Handles.Button and a circlecap through an editor window. I'm using a recursive method to dig down through the hierarchy, which lets me draw a button on each transform and detect when it's selected, then set Selection.activeObject.
Answer by AnomalusUndrdog · Aug 11, 2017 at 10:15 PM
The Handles class can draw lines that are above any mesh in the Scene View (it will do the one on the right, in your screenshot).
Most of the things you can do in Gizmos can also be done in Handles. It has Handles.DrawLine() which is equivalent to Gizmos.DrawLine(). There's Handles.color which works the same as Gizmos.color.
However they don't have the same amount of methods, so you'll have to figure out how some of your Gizmos code should be converted to Handles. For example, Gizmos.DrawCube() lets you draw a solid cube but Handles doesn't have that. It has Handles.DrawWireCube(), which, as can be inferred from the name, only draws a wireframe of a cube. There is Handles.CubeHandleCap() which can be used to draw cubes like Gizmos.DrawCube() does, but the Gizmos method allows you to stretch and squash the cube, while Handles.CubeHandleCap() can't.
Handles has a few more methods that Gizmos doesn't have. For example there's Handles.DrawSolidRectangleWithOutline() which lets you draw a quad.