Table of Contents

Contexts

DebugDraw can be used within the Update, LateUpdate or FixedUpdate loop, at edit time, or to draw gizmos with minimal changes required.

By default the DebugDraw mode is set to Update so no changes are required for running inside the Update loop.

FixedUpdate

To draw from the FixedUpdate loop, simply set Draw.UpdateMode to FixedUpdate during initialisation.

void Awake() {
    Draw.UpdateMode = UpdateMode.FixedUpdate;
}

void FixedUpdate() {
    // Drawing can now be safely done from within `FixedUpdate`.
    Draw.Line(new(0, 0, 0), new(1, 1, 1));
}

Editor and Gizmos

Drawing will works seamlessly at edit time without any changes required.

[ExecuteAlways]
public class EditorDemo : MonoBehaviour  {
    void Update() {
        Draw.Arrow(new(0, -1, 0), new(0, 1, 0), Color.yellow);
    }
}
void OnDrawGizmos() {
    Draw.Arrow(new(1, -1, 0), new(-1, 1, 0), Color.yellow);
}

// The `DrawGizmo` attribute can also be used for more control.
[DrawGizmo(GizmoType.Selected)]
static void DrawGizmosSelected(GizmosSectionAlways section, GizmoType gizmoType) {
    Draw.Arrow(new(-1, -1, 0), new(1, 1, 0), Color.green);
}

[DrawGizmo(GizmoType.NonSelected)]
static void DrawGizmosNonSelected(GizmosSectionAlways section, GizmoType gizmoType) {
    Draw.Arrow(new(-1, -1, 0), new(1, 1, 0), Color.red);
}