- Home /
DrawGizmo attribute render draw depth bug?
I've noticed that when using the DrawGizmo attribute instead of the OnDrawGizmos method, that the gizmo draw order becomes apparently random. Am I doing something wrong here or is this actually a bug?
This works perfectly fine:
using UnityEngine;
public class OnDrawGizmoTest : MonoBehaviour
{
void OnDrawGizmos()
{
Gizmos.color = Color.cyan;
Gizmos.DrawSphere(transform.position, 1);
}
}
However, replacing OnDrawGizmo with the script below causes issues:
using UnityEngine;
using UnityEditor;
public class MyScriptGizmoDrawer
{
[DrawGizmo(GizmoType.NonSelected | GizmoType.InSelectionHierarchy | GizmoType.Pickable)]
static void DrawGizmoForMyScript(OnDrawGizmoTest scr, GizmoType gizmoType)
{
Gizmos.color = Color.cyan;
Gizmos.DrawSphere(scr.transform.position, 1);
}
}
drawgizmodepthbug.png
(33.1 kB)
Comment
This appears to indeed be a bug and has been submitted to Unity. Issue ID 794957
Your answer
![](https://koobas.hobune.stream/wayback/20220612080341im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to Display UI at a Specific "Depth" (Render Depth) in 3D Space 1 Answer
Scene view stretches camera frustum gizmo 4 Answers
What is a difference between GizmoType.Active and GizmoType.Selected? 1 Answer
Rendering when 'moving a character controller through a "portal"' 2 Answers
Multiple Cameras: why are my gizmos not rendered in the game view 1 Answer