Visual debugging in Scene View with Handles.label

Sometimes we need to see info about objects during playtime for debugging.

Lets say, we’re making a destructible environment and we need to debug the health of objects in the scene.

OnDrawGizmos() is a Unity callback, like Update() and FixedUpdate(), but only for the editor’s scene view. It isn’t called all the time, like update or fixedUpdate, but only when something “changes” in the scene.

And the Handles class is the API for those arrow things that lets us do scaling, positioning and all that jazz in the scene view. We can define our own version of these but for the sake of debugging, we can use the .Label() function to print some info on our object.

And just like that, we have visual debug info in the scene.