Vertx.Debugging
Debugging utilities for Unity
Install / Use
/learn @vertxxyz/Vertx.DebuggingREADME
Fast editor debugging and gizmo utilities for Unity.
Uses instanced rendering to draw shapes efficiently.
[!NOTE]
Unity 2022.2+ (all features) - Version 3.0.0 and above.
2019.4+ No jobs and burst support, older API.Should support all render pipelines.
Supports drawing from jobs and burst. This package depends on Burst and Mathematics.
All shapes are wireframe. There is currently no support for solid shapes planned.
https://user-images.githubusercontent.com/21963717/194199755-a63d8ebc-0cc7-4268-9316-78f7d4fbea1a.mp4
Usage
<details> <summary>Shape drawing</summary> <table><tr><td>Example
// Draw a sphere with the specified color.
D.raw(new Shape.Sphere(position, radius), color, duration);
// Draw green sphere if nothing was hit,
// or draw a red sphere if something was.
D.raw(new Shape.Sphere(position, radius), hit, duration);
// Casts draw in green, with red where hits were detected if no color is provided.
// Cast color and hit color can be overrided manually.
D.raw(new Shape.SphereCastAll(position, direction, radius, hits, hitCount, 10), duration);
Available contexts
You can call these methods from most places, Update, LateUpdate, FixedUpdate, OnDrawGizmos, and with ExecuteAlways/ExecuteInEditMode.
If drawn from a gizmo context, duration parameters will be ignored. Gizmos.matrix works, Gizmos.color is unsupported. Gizmos are not pickable.
Code stripping
Calls to these methods are stripped when building. You do not have to remove code or use defines.
If your code spans many statements, only the method call will be stripped.
Example
You can replace calls to Physics and Physics2D methods with DrawPhysics and DrawPhysics2D to simply draw the results of a physics operation.
int count = DrawPhysics.RaycastNonAlloc(r, results, distance);
Use DrawPhysicsSettings.SetDuration or Duration to override the length of time the casts draw for. You will need to reset this value manually.
Calls to Duration cannot be stripped, I would recommend using SetDuration if this is important to you.
Code stripping
The drawing within these methods will be stripped, and the original method is attempted to be inlined, but this is not consistent.
A single method call doesn't matter when compared to a physics operation, but you can completely strip these calls by instead declaring:
#if UNITY_EDITOR
using Physics = Vertx.Debugging.DrawPhysics;
#endif
</td></tr></table>
</details>
[!NOTE]
Gizmos must be enabled in the view.
3D gizmos support fading, but may be inconsistent between Unity versions.If you find you have rendering issues like upside-down depth testing, or artifacts in the game view: This is a Unity bug.
You can disable Depth Write and Depth Test in the problematic view using the settings in Project Settings > Vertx > Debugging.
If you're on a version of Unity where the settings UI doesn't work, it's another Unity bug, thanks Unity!
Shapes
Drawable shapes and casts are contained within the Shape class. You can statically import the class if you use them often:
using static Vertx.Debugging.Shape;
<details>
<summary>Shape list</summary>
General
| Name | Description |
|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Text | A label in the scene at the provided position. (Text respects 3D gizmo fade distance)<br/>Not currently supported in jobs. |
| ScreenText | A label in the top left of the view.<br>Draws using an Overlay in the Scene view when available.<br/>Not currently supported in jobs. |
3D
Shapes
| Name | Description |
|--------------------------------------------------------------|--------------------------------------------------------------------------------------------------|
| Sphere<br>Hemisphere<br>Box<br>Capsule<br>Cylinder | 3D shapes. |
| Arc | An arc (using Angle[^1] to define its length). |
| Annulus | An annulus or annulus sector. |
| SurfacePoint | A ray with a circle to indicate the surface. |
| Point | A point without a specified direction. |
| Axis | An XYZ direction gizmo. |
| Arrow<br>ArrowStrip | An arrow vector, or a collection of points forming an arrow. |
| Line<br>LineStrip | A line, or a collection of points that make up a line. |
| DashedLine | A dashed line. |
| HalfArrow | An arrow with only one side of its head. Commonly used to represent the HalfEdge data structure. |
| Arrow2DFromNormal | An 2D arrow aligned in 3D space using a normal vector perpendicular to the direction. |
| Plane | A 3D rect drawn around a point on the plane. |
| Cone | A cone (with adjustable end radius, making a conical frustum). |
| Pyramid | A pyramid. |
| Frustum | A camera frustum. |
| FieldOfView | A 3D field of view, a spherical sector. |
| MeshNormals | The normals of a mesh. |
| Catenary | Similar to cable hanging between two points. |
| Ray | A line from a position and a direction vector. |
| Ray (Built-in) | Fallback to Ray. |
| Vector3 (Built-in) | Fallback to Point. |
| RaycastHit (Built-in) | Fallback to SurfacePoint. |
| Bounds (Built-in) | Fallback to Box. |
| Collider (Built-in) | Fallback to the correct shape matching the collider type (primitive colliders only). |
Casts
| Name | Description |
|-------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Raycast<br>Linecast<br>SphereCast<br>BoxCast<br>CapsuleCast | Using similar parameters as<br>Physics.Raycast<br>Physics.Linecast<br>Physics.SphereCast<br>Physics.BoxCast<br>Physics.CapsuleCast<br>with an optional RaycastHit result. |
| <br>RaycastAll<br>SphereCastAll<br>BoxCastAll<br>CapsuleCastAll | RaycastHit[] results using similar parameters as<br>Physics.RaycastAll<br>Physics.SphereCastAll<br>Physics.BoxCastAll<br>Physics.CapsuleCastAll |
2D
Shapes
| Name | Description |
|------------------------------------------------------------|--------------------------------------------------------------|
| Circle2D<br>Box2D<br>Area2D<br>Capsule2D<br>Rect | 2D shapes.
