If you set "Handles.zTest = CompareFunction.Less" this has no effect on "Handles.DotHandleCap" it only works with "Handles.DotCap" but this function is obsolete. So how can I solve this or is this a bug in Unity? My test code: Code (CSharp): [CustomEditor(typeof(MyTestCode))] public class DotHandleTestEditor : Editor { protected virtual void OnSceneGUI() { Handles.zTest = CompareFunction.Less; Quaternion lookAtRot = Quaternion.LookRotation(Camera.current.transform.position); float size = HandleUtility.GetHandleSize(Vector3.zero); if (Handles.Button(Vector3.zero, lookAtRot, size * 0.05f, size * 0.07f, Handles.DotCap)) Debug.Log("zTest works fine on this one"); lookAtRot = Quaternion.LookRotation(new Vector3(20, 0, 0) - Camera.current.transform.position); if (Handles.Button(new Vector3(1,0,0), lookAtRot, size * 0.05f, size * 0.07f, Handles.DotHandleCap)) Debug.Log("zTest is not working on this one"); } }
Okey I dit some more research and I looked in de source code and I found this. Code (CSharp): //Unity 2018.1 public sealed class Handles ... [Obsolete("Use DotHandleCap instead")] public static void DotCap(int controlID, Vector3 position, Quaternion rotation, float size) { if (Event.current.type == EventType.Repaint) { position = Handles.matrix.MultiplyPoint(position); Vector3 b = Camera.current.transform.right * size; Vector3 b2 = Camera.current.transform.up * size; Color c = Handles.color * new Color(1f, 1f, 1f, 0.99f); HandleUtility.ApplyWireMaterial(Handles.zTest); GL.Begin(7); GL.Color(c); GL.Vertex(position + b + b2); GL.Vertex(position + b - b2); GL.Vertex(position - b - b2); GL.Vertex(position - b + b2); GL.End(); } } public static void DotHandleCap(int controlID, Vector3 position, Quaternion rotation, float size, EventType eventType) { if (eventType != EventType.Layout) { if (eventType == EventType.Repaint) { position = Handles.matrix.MultiplyPoint(position); Vector3 b = Camera.current.transform.right * size; Vector3 b2 = Camera.current.transform.up * size; Color c = Handles.color * new Color(1f, 1f, 1f, 0.99f); HandleUtility.ApplyWireMaterial(); GL.Begin(7); GL.Color(c); GL.Vertex(position + b + b2); GL.Vertex(position + b - b2); GL.Vertex(position - b - b2); GL.Vertex(position - b + b2); GL.End(); } } else { HandleUtility.AddControl(controlID, HandleUtility.DistanceToRectangle(position, rotation, size)); } } As you can see DotCap uses the zTest Code (CSharp): HandleUtility.ApplyWireMaterial(Handles.zTest); And DotHandleCap does not use the zTest Code (CSharp): HandleUtility.ApplyWireMaterial(); So I think the Unity team forgot to put it in there.