Search Instagram Twitter Facebook Spotify Grid Tag Date Folder Chat Pencil

Debug Console or: How Did No One Tell Me About Implementing This Incredibly Useful Tool Two Years Ago

I spent the past few days setting up a debug console in the game. I actually started working on this back at the beginning of January, but didn’t get past implementing the basic code. Also, that was in the old version of the game, and now I’ve set it up so that it’s in the version I’m making in Unity 5, in which I’m going through all the basic mechanics and refining them.

Before I get to the details, I’d like to talk about the inspiration that finally got me to take the time and set up this debug console. There are three specific moments:

Inspiration

1) I was in LA during IndieCade, and hanging out Glitch City. Brendon Chung was showing me his game Quadrilateral Cowboy. At one point, he needed to make some changes or fixes, and so he pulled up the console, type in some commands, and right away, those changes happened. Having not played a lot of PC FPS games when I was younger, I had never seen thsi before. I was like “whoa, what was that!?”. Brendon explained that this is actually a feature of the Doom 3 Engine.

2) I was having a conversation on twitter about playtesting with my friend Frank, who used to do QA at Harmonix. Frank explained that Harmonix took playtesting very seriously, and for each session, they would have an engineer as well as a designer on site. They would ask the player to try something, and then the engineer would change the values right away, and ask the player to try again until they got the feel right.

This was pretty mindblowing to me. The idea of making real-time changes during a playtest session had never occurred to me. I would implement something, put out a build, have people play it, then take their feedback afterwards and try to address them with new changes. Then I’d output another build, schedule another playtest session, and see if it this was fixed.

3) I did a group critique session last month with a bunch of Chicago game devs. I was the first to present, and during my demo, I ran into this bug that got me stuck in a wall. There was no way to fix this without restarting the game, and replaying through all the previous areas again, so I ended up describing my problem on paper. It worked, but it really wasn’t ideal.

Then Sean Hogan demoed his game Even the Ocean, and as we were giving him suggestions, he was able to pull up an in-game editor and start tweaking values, moving objects around, and get immediate feedback right away. It was pretty incredible.

Because I’m working on game feel aspects now, there is a lot of tweaking. Having the ability to make real-time changes to variables is invaluable.

Old Method

I should clarify that even in the past, I was displaying values and variables when debugging. In the above picture, you can see that I was printing various values in the top left corner of the screen.

However, most of these were one liners, like

1
GUI.Label(new Rect(10, 10, 100, 20), "Gravity Normal: " + gravityNormal.ToString());

When I no longer needed it, I would comment it out.

Invariably, this led to a bunch of commented out lines at the bottom of the script printing out different variables. And at some point, I would just delete it because it was making the code look all cluttered.

I would also use hot keys, such as hitting ‘p’ to increase movement speed. But these do get pretty hard to remember when you have a bunch of them, and there’s also the risk of players hitting a key accidentally and screwing themselves up.

Console

I got the code for the console from here: https://github.com/mikelovesrobots/unity3d-console

It was pretty straightforward to set up.

Only thing was I had to comment out this line:

GUI.TextField(bounds, “”, 0);

in the script ConsoleNamedKeyBugFix.cs

because it was causing this really small black square to appear in the upper left corner when the console was closed:

This image above is amplified and cropped, so it was quite small, but it did bother me tremendously.

Anyway, the way it’s set up is that now, I have a series of commands registered:

1
2
3
4
5
repo.RegisterCommand("help", ShowHelpText);
repo.RegisterCommand("list_commands", ShowCommandList);
repo.RegisterCommand("show_carry_method_text", ShowCarryMethodText);
repo.RegisterCommand("show_player_states", ShowPlayerStates);
repo.RegisterCommand("set_rotate_speed_divisor", SetRotateSpeedDivisor);

Commands like show_player_states turns on a bool in the script controlling player movement, which then displays the values on the screen.

I also have commands that allow me to change values, like set_rotate_speed_divisor.

I have a variable which I divide time with to speed up and slow down the rotation speed, and this allows me to change it in the build of the game.

It doens’t save it, but I am at least able to note it down, which helps a lot.

Here’s a gif showing the console in action:

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.