Unity has many tools for debugging spacial problems, though each tool has its own benefits and drawbacks.
By drawing lines and shapes in the Scene and Game view you can validate assumptions about positions and directions used in code.
Unity's Debug.DrawRay and Debug.DrawLine are valuable tools for debugging 3D (and 2D) information. The API is simple to use, but is only capable of drawing basic lines.
Learn more.
MonoBehaviour's OnDrawGizmos and OnDrawGizmosSelected callbacks allow the use of Gizmos and Handles APIs. The APIs support more complex shapes, but cannot be used outside of specific callbacks.
Learn more.
The Physics Debugger is a built-in tool window for visualising 3D physics shapes, collisions, and queries.
Learn more.
Vertx.Debugging and Raycast Visualization both have drop-in replacements for physics queries (casts, overlaps, hits, checks) that display their bounds and results.
Vertx.Debugging is a debugging package for drawing wireframe shapes.
It has drop-in replacements for physics queries (casts, overlaps, hits, checks), many extra shapes, and can draw labels in the scene.
It is designed for editor debugging and most functions will be stripped when built. Versions 3.0.0 and above support jobs.
Raycast Visualization is a drop-in replacement for Physics queries (casts, overlaps, hits, checks).
It is designed for editor debugging and most functions will be stripped when built.
ALINE is a paid alternative that is intended to draw shapes in the editor and builds, and supports drawing from jobs.
Shapes is a paid alternative that is designed to draw good-looking lines for editor and builds.
The API is not designed to be used inline as others
If you are using Entities (ECS), Unity Physics (com.unity.physics) has PhysicsDebugDisplaySystem, which contains static helper methods for drawing wireframe shapes from jobs.
If you do not understand what Entities is, you should not use this package for debugging.
There is also the Physics Debug Display authoring component that has toggles for similar debugging to the Physics Debugger.
| Name | 2D/3D | Job System / Burst | Platforms | Call site | Price | Focus |
|---|---|---|---|---|---|---|
| Draw functions | Both* | No | Editor | Anywhere†| Built-in | |
| Gizmos | Both* | No | Editor | Gizmos callbacks | Built-in | |
| Handles | Both* | No | Editor (strict) | Gizmos and OnGUI callbacks | Built-in | |
| Physics Debugger | 3D only | No | Editor | Built-in | Ease of use | |
| Unity Physics | Both* | Yes | Editor | Entities | Built-in | Performance |
| Vertx.Debugging | Both | 3.0.0+ | Editor | Anywhere | Free | Ease of use, performance |
| Raycast Visualization | Both | No | Editor | Anywhere†| Free | Ease of use |
| ALINE | Both* | Yes | Any | Anywhere | $30 | Performance |
| Shapes | Both | No | Any | DrawShapes callback | $100 | Looks, Ease of use |