Draw functions#

Unity's Debug.DrawRay and Debug.DrawLine are valuable tools for debugging 3D (and 2D) information.
By drawing lines in the Scene and Game view you can validate assumptions about positions and directions used in code.


Lines that aren't drawn continuously will only appear for a single frame, to counteract this a duration can be provided as the fourth parameter.
Make sure that the variables used in your draw functions are the same as those used by the functionality you are debugging.


Note that DrawRay takes a position and a direction.
Scaling a normalized vector will produce a vector with that length. This can be done here to make the output more visible.

Debug.DrawRay(transform.position, direction * length, new Color(0.6f, 1f, 0.2f));

If you're passing two positions to this function the results will be unexpected. Use DrawLine instead.


Debug.DrawLine(transform.position, Target.position);


To display gizmos in the Scene or Game view, toggles for each must be enabled.

Scene view gizmo toggle

Return to visual debugging.