Debugging as a Solo Game Developer: My Workflow

I am a Unity C# developer, educator, and writer from Canada.
Search for a command to run...

I am a Unity C# developer, educator, and writer from Canada.
I agree! I always heard that debugging is the worst part of coding but I actually quite enjoy it. :)
Great article! I often miss doing the first step which makes me do a lot of work than expected 😆😆
Ah yes, I do this too! Actually writing out the steps has helped me solidify them in my mind. Do you use Sourcetree too?
In this series, I will teach some of the basics for developing C# games in Unity, one of the biggest game engines on the market.
Welcome to the first post in a new series I'm calling Beginner's Guide to Unity. I created this series for anyone who is interested in learning game development in Unity but isn't sure where to start. In this article, we will go over the basics of se...
Introduction 👋 Hi, I’m Taryn! I’m a Unity dev who created a small project for Hacktoberfest 2023. In this devlog, I’ll introduce you to the project and talk about my goals for Hacktoberfest as a game developer. Tiny Troves of Dev Wisdom First, let’...

In today's post, I'll be talking about my latest Unity project, which is an updated version of the first game I ever published online. Introducing....No Crooks On Christmas! I decided to upgrade No Crooks On Christmas as a kind of challenge to mys...

Level up your game development skills by learning to spot and fix these common Unity errors.

Learn the differences between a project name and a product name

It's the end of the first week of my first time as an official Hacktoberfest participant! There have been many ups and downs this week, and I thought I'd summarize them here so that others can see what the experience of a first-timer is like. So wit...

Debugging. 🪲
Like it or not, it's a fundamental part of being a developer.
Over the past year, I've learned to like debugging, and even refactoring, my code. There's a certain sense of satisfaction that comes with cleaning up code and making it neat and tidy. Perhaps you've felt it too.
In this article, I'm going to walk you through the steps I take to debug my C# code as a Unity developer. Even if you don't work with Unity, hopefully this article will inspire you to reflect on your own debugging process and better appreciate all of the hard work you do to make your code shine. 🌟
Before I get started, I wanted to talk a little bit about when to debug in Unity. Generally, I don't think you need to fix a bug the second you find it, unless it's game-breaking. With newer versions of Unity, I've been having trouble testing my game in the editor without fixing error warnings first. This is a bit of a pain because it means I have to stop what I'm doing and immediately address each and every bug, even if it is minor and unrelated to the main game mechanics. But in the long run, I kind of appreciate being forced to do this since it means less trouble for my code down the line.
The Console is where debug messages appear in Unity. You can find the Console at the bottom of the Unity editor window.
Now let's jump into the meat of this article and look at the five main steps I take each time I try to fix a bug in a Unity project.
I use Sourcetree to back up my work and here is a simplified version of my workflow:
Launch Sourcetree.
Stage any unstaged files in the project I'm backing up.
Write a blurb in the Commit text box to summarize the changes I've made. Sometimes I will just note that this is a backup commit of the project before I add a new feature or attempt some heavy debugging.
Click Commit.
Click Push to back my project up to a remote repository on GitHub.
PS. If you are a game developer who is looking for a solid introduction to using Unity with Sourcetree, I highly recommend GameDev.tv's Get Git Smart Course.
An image of the comment box for a commit in Sourcetree.
Next, I turn my attention to the Console and read any error messages or warnings that have popped up. Double-clicking these messages will open the script (if applicable) where the error occurs, and I can usually go from there.
Once you've worked in Unity for a while, you'll become familiar with certain types of errors.
Here are some examples you might see:
An image of a common error message in the Console. In this example, I have forgotten to add a scene to the project's Build Index.
Often the Console will suggest that the problem is caused by an incorrect or missing setting in the Inspector. So the next thing I'll do is look at the Inspector and check whether anything is amiss there.
Here are some of the things to be on the lookout for in the Inspector:
OnClick() event for a button
An image of a common error message in the Console. In this example, I have forgotten to drag and drop a game object into a Serialized field in the Inspector.
Next, I'll open up my scripts and see if I can problem solve there.
Here are some common issues that you may run into:
GetComponent. You may be trying to access a component which does not currently exist on the game object. To solve this, add the component via the InspectorOnce I've gone through the steps above and made sure that the problem isn't with something I've forgotten to do in the Inspector, then I'll start using Debug.Log or print() in my scripts. Usually by this time I have a pretty good idea of where the problem exists. I like to write my Debug.Log or print() statements with a string statement at the beginning so that I don't lose track of what I'm testing for.
So for example, if I was testing to see whether a variable was returning True or False, I'd write:

And the output would look like this in the Console:

I use this method to follow the line of logic through my scripts until I have located and fixed the problem. One last piece of advice: once you are done with a debug statement, make sure you either delete it or comment it out in your scripts. Otherwise your Console will become very cluttered with messages!
Now it's your turn: how do you tackle debugging in your projects? I'd love to hear any tips or tricks you have in the comments below.