Cities: Skylines Wiki

This page describes how you can debug your mod.

DebugOutputPanel

The debug output panel can be opened in game with F7.

ModTools

The recommended way for debugging is by using the Unity's debug logging API.

using UnityEngine;

Debug.Log(...);

The downside is that you can not see these logs in the game unless you use ModTools. It's really recommended to subscribe to ModTools (requires restart after install). It offers way more than just having a better console so it's really a must have if you're going to make (advanced) mods.

Output log

If you don't want to use ModTools you can locate the logged messages in the output log. <%STEAM%>\steamapps\common\Cities_Skylines\Cities_Data\output_log.txt

Alternative Logging Method

An alternative for logging would be to directly add messages to the DebugOutputPanel. When using this method please prefix your messages with your plugin name.

using ColossalFramework.Plugins;

DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "<message>");

Debugging with a debugger such as Visual Studio 2017 or VS Code

This is for Windows:

  • For Visual Studio 2017 in the installer, (or Tools->Get Tools and features), under Workloads, Mobile & Gaming, check the "Game development with Unity"
  • For VS Code add C# and Mono Debug from the extensions in the marketplace
  • Build mono.dll from source https://github.com/thardie/mono/tree/unity-5.6
    • Alternate prebuilt www.orcas.net/cities_skylines/mono.dll
  • Rename your original mono.dll (in C:\Program Files (x86)\Steam\steamapps\common\Cities_Skylines\Cities_Data\Mono)
  • Put the downloaded mono.dll in that directory
  • Check your cities still works.
  • Edit your system environment variables (Right click This PC/My computer->Properties->Advanced System Settings->Environment Variables->User Variables->New...
  • Add Variable named "MONO_DEBUGGER_AGENT", value "transport=dt_socket,address=127.0.0.1:56000,defer=y"
  • Click OK, OK, OK.
  • Make sure steam is NOT running.
  • Launch cities any way you want.
  • Open debugger (VS 2017 with your mod's code loaded, Debug->Attach Unity Debugger->Input IP->127.0.0.1:56000) (For VS Code, see launch.json below)

VS Code launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Mono",
            "request": "attach",
            "type": "mono",
            "address": "localhost",
            "port": 56000
        }
    ]
}

To disable debugging, rename or remove the environment variable. You'll need to restart Steam for it to take effect.

See also