Visual Debugging in Unity3D

Printf() debugging ( or log debugging, or whatever you want to call it ) is a common go to method every programmer found himself resorting to at some point, usually when more sophisticated methods failed to provide insights.

The concept is quite simple – it involves adding log commands to key points in the program (usually supplemented by an assortment of swear words) and inspecting the resulting output log, trying to find abnormalities in either execution flow or interesting data fields.

Now to tie this introduction to the title of the article – gathering data from the program is only part of the process of debugging. After gathering data we need to analyze it, which can prove to be quite tedious and very error prone in many cases, especially when trying to trace changes in data through hundreds of entries. That problem too has a solution though… are you ready for it?


Math.Sin and SIn Approximation. Evaluating accuracy at a glance.

Math.Sin and Sin Approximation. Evaluating accuracy at a glance.

By visualizing our data we can analyze it much more efficiently, we can understand trends and spot abnormal values at a glance. Sounds good so far, doesn’t it? So where’s the catch?

The catch is that as opposed to logging data, which is very simple an accessible (in most languages you can use a one liner to output data to the output stream), visualizing said data is usually not something we can simply get out of the box.

With that realization I’ve decided to write a small utility to help me graph data. Another requirement I’ve added on the fly as I was getting to coding was to make sure the solution can be easily integrated and removed – which translates into a minimal source file count and no special scene setup requirements.

You can grab the source files and documentation from GitHub. It’s nothing fancy, but it’ll save you the 2 hours it took me to put it together. Also, if you’re interested in a working example of the GL class, it’s worth a look.

Graph script settings.

Graph script settings.


1. Source files on GitHub

2. Unity Scripting Reference: GL Class

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *