Your game logic is invisible until you make it visible. OnDrawGizmos draws debug shapes right in the editor so you can see what your code is actually doing – detection ranges, raycasts, vision cones, anything abstract.
When you’re building AI behavior or game mechanics, a lot of logic happens invisibly in code. Your AI checks if an enemy is in range, raycasts for obstacles, calculates vision cones – but you can’t see any of it running. This makes debugging frustrating and slow.
OnDrawGizmos is a built-in Unity method that solves this. Drop it in your script and draw debug shapes right in the editor scene. A detection range becomes a red sphere. A raycast becomes a green line. Complex logic becomes immediately visible.
The key is that OnDrawGizmos only runs in the editor, not in builds. It’s pure debugging. You draw once per frame, and the editor shows it in real time. Change a value and watch the sphere resize. Move your object and watch the raycast line follow it.
This saves hours. Instead of sprinkling Debug.Log statements or running the game and guessing what’s happening, you see your logic running live. It’s one of the fastest ways to catch bugs and understand your own code.
void OnDrawGizmos() {
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, 5f);
Gizmos.color = Color.green;
Gizmos.DrawLine(transform.position, transform.position + transform.forward * 10f);
}If you debug a lot, save this one.
#unitytips #gamedevelopment #gamedev #unity #csharp #softwaredevelopment #unitydeveloper #indiegamedev



