Join Chris Byers for an in-depth discussion in this video Walk through the C# Debug API, part of Debugging Scripts in Unity.
- Before we dive into Unity, I first want to familiarize you with the API that wraps the debug features into a single class called Debug. So let's just take a minute and walk through each member of the class, and briefly explain what it does. So the website is at docs.unity3d.com and have it up available here, and the first flag we have on the screen is DeveloperConsoleVisible, what this allows you to do is open and close a console that's only visible on the deployed applications, that allows testers to see any errors that are logged through the log error methods.
The isDebugBuild flag allows us to determine if we're in a build setting where the development build flag is set. Again, this is useful if you want to check and make sure that you're in a development build before printing out Log information because that's going to use CPU overhead that you really don't want to used on a release deployed app. The Break option pauses the editor, so we could put a break call anywhere inside the code and actually pause the editor at that point, and obviously that's useful when you want to stop the editor and go inspect all the objects within the hierarchy in the scene.
ClearDeveloperConsole allows you to clear the errors from the developer console, that's straight forward. DrawLine and DrawRay which we are going to talk about in a little bit are going to allow you to see a visual line or ray on the screen, and Log, LogError, LogWarning are all three log entries that are going to go to the Unity Console which we'll discuss in a future video. LogFormat, LogWarningFormat and LogErrorFormat allow you to add composite formatting using the MSDN rules so you can specify floating point, precision, single text alignment, and other text alignment, things like that.
Rich texts is also available in all of the Log calls so you can take a look at the information on the website as well. Unity provides a good developer resource for all the available options for logging in rich text as well. All the Log methods except for the LogException method provide a second option, called the Context Object, the Context Object allows you to associate the Log call with an object in the scene, so that when you click on the entry in the Unity Console you'll see that that object is highlighted in the hierarchy.
So now that we have an understanding of what the Debug class offers we're going to look at the Debug class in future videos and how to use that in the Unity API using the MonoDevelop debugger.
- Working in the Unity console
- Brute force logging
- Debugging in Scene view
- Handling exceptions
- Running integration and unit tests
- Tips for debugging on mobile platforms