So I was working on a project that targets mobile and I’d run into a problem that didn’t replicate in editor or on Android, only on iOS. I really just wanted to put a bunch of logs in and see what was happening. I wanted an in game dev console. If you aren’t sure what I mean by that, if you’ve played with an Id or Valve game you’ve probably enabled developer console at some point, seen logs pop up in the top left or hit ` to change maps or enable net_graph.

Similarly, Bethesda games tend to have powerful in game consoles that can execute the same sort of commands as the scripting language. Which leads to amazing things like this Monster Factory Fallout4.

So I went hunting, surely this is something people have already attempted, if not solved.
Yep, people have tried this before.

To fix my problem I just needed to see logs so I went with something very similar to Consolation. It uses the old immediate mode Unity GUI calls. I didn’t care for that, pixel based sizes and GUI Skins are not fun to work with. The idea is the same though, hook up Unity Log Callback and append some strings to an auto scrolling UI.Text. I also made it fade out nicely with a LeanTween.

It did let me find my problem, it was a file and directory formatting problem that meant a file was failing to be found on iOS. Fixed.

I left the dev console enabled and found that I like having the logs visible during development. It makes me feel more aware of how the game is running and more connected to the code that I wrote. Rather than it feeling like a disconnected artifact of a build process. For this particular project I had already started building a developer only panel, that gives run-time access to a number of slider values and player resets and unlock shortcuts. So the logical step was to make this an actual console not just a way of seeing logs and move the functionality that I was manually building and adding to the . For this I looked to GConsole as it was simple to integrate and small enough that I could read all the code myself if it didn’t meet my needs. I quickly found that I wanted more from it.

I want to keep working on this and add more features to it, no one of the consoles I found that already exists quite does all the things that I want.

So here are some non-ordered requirements;

  • See logs
    • preview as they come in
    • expand console to scroll back through them
  • Run commands, eg quit app, load a scene, give player xp
  • Inspect and change vars, eg player’s hp, gravity, spawn timer
  • Inspect and change cl vars, eg resolution, vsync
  • Get snapshots of data, eg. GameObject hierarchy, Active enemies
  • Not have to reinvent all functionality that exists elsewhere just for the console
    • This is crucial, if functionality that already has to be manually wrapped or duplicated for the console to access it, then it just doesn’t get done as the cost of get that functionality wrapped and configurable by the console vs adding new features or bug fixing or polishing just doesn’t hold up.

Some examples of what we would like the console input and outputs to look like

GConsole has a simple to understand code base, part of how it achieves this is by only accepting Func<string, string> as methods. This pushes the developer to wrap existing functionality in a function that takes a single string that could be anything from the user. I know that I’d get sick of writing string extraction and conversion code and wrapping existing functionality.

CUDLR is awesome, it operates like a slim http server in your game that you write custom routes (routes a common web concept). It’s designed to be able to remotely debug and see the console via the browser, so locally or if you know the IP you can get the console logs and send commands and fetch routes. But it ships with no built in way of doing that from within the game itself which I’d want to do when I’m on a phone or tablet. CUDLR still gives a string[] as the parameter to it’s commands and would require custom wrapping of existing functions.

I’m going to keep experimenting and pushing this forward. Should you wish to see some in progress code you can check out console stuff is currently in UnderConstruction/ConsoleHelper

Part 2 here.