Unity Gizmos - What They Are & Why They're Useful

 Unity Gizmos

Many Unity developers when they are starting out or for that matter even after they are proficient in Unity, they may never come across / never use it.
Gizmos are really powerful debugging tools that are provided in Unity and they run in the scene view of the editor. Iteration times (implementing something & testing ) can really be improved a lot because you able to interact with the scene in way that is custom fit to your needs and requirements.
I usually use Gizmos to make a prototype before I make a prototype, which I'm sure a lot of you do.
As Gizmos runs in the editor scene view and because it comes featured with a lot of debugging tools right out of the box, I don't have to implement my own.
To make custom Gizmos you have to write it in the 'OnDrawGizmos' or 'OnDrawGizmosSelected' functions. These are just like the Start() & Update() functions that are there.
The OnDrawGizmos function is called every frame in the editor whereas the OnDrawGizmosSelected function is called only when the specified component is selected in the scene view.
procedural mesh view with unity gizmos
Vertices & Edges Shown Of A Procedural Mesh
Now you might be able to understand why this is really useful when you want to visualize whats happening in your code without taking the time to code it within the game itself.
Almost all of the built-in components in Unity have their own custom Gizmos that is shown in the editor.
Like the AudioSource component with it's audio range sphere around it or the spotlight that shows the direction and radius of the light.
Spotlight Gizmo In Unity
The most common parts of the Gizmos API that you will end up using are probably these 4:
  • DrawLine :- Draws a line between two Vector3s.
  • DrawRay :- Draws a ray from a point and extends out in a particular direction.
  • DrawCube :- Draws a cube at specified point with certain dimensions.
  • DrawSphere :- Draws a sphere at certain point with a specified radius.
  • Color :- Sets the colour that the rest of the following Gizmos will use. 
I hope you have been introduced to world of easy debugging and faster iteration times.😀.
Support Bitshift Programmer by leaving a like on Bitshift Programmer Facebook Page and be updated as soon as there is a new blog post.
If you have any questions that you might have about shaders or unity development in general don't be shy and leave a message on my facebook page or down in the comments.