Debugging Mods

From Cities: Skylines Wiki
Jump to navigation Jump to search

This page describes how you can debug your mod.

DebugOutputPanel[edit | edit source]

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

ModTools[edit | edit source]

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

using UnityEngine;


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[edit | edit source]

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[edit | edit source]

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[edit | edit source]

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
    • Alternate prebuilt
  • 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=,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-> (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[edit | edit source]