Chapter 2. Debugging
Debugging is the process of finding, identifying, and fixing bugs (errors or mistakes) in your code, and there are many ways to achieve this. To script effectively, you'll need to be aware of the most common workflows and toolsets available to you for debugging in Unity. Before considering them further, however, it's important to be aware of the general limitations of debugging and what it cannot achieve. Debugging is not a magical cure-all to remove all bugs and guarantee an error-free application. The computer scientist Edsger W. Dijkstra said, "Program testing can be used to show the presence of bugs, but never to show their absence". The crucial point is that during testing, you might encounter one or more errors. These errors can be identified, tested, and repaired through debugging. Yet, your tests—though perhaps extensive and careful—will never cover every possible case or scenario on every hardware platform under all conditions, as these combinations could be practically infinite. So, you can never be absolutely certain to have found all the possible bugs. Even on the release day, there could still be bugs in your game, which your testing couldn't detect. Of course, there might actually be no bugs remaining at all, but you cannot know this with absolute certainty. So, debugging is not about achieving an error-free application. Its aims are more modest. It's about systematically testing your game in many common and reasonable situations to find and correct as many errors as you encounter or, at least, as many severe errors as your time and budget permits. In any case, debugging is a critical part of scripting, because without it, you will have no way of tracing and fixing errors. Debugging techniques range from simple to complex, and in this chapter, we'll cover a broad spectrum of them.