Debugging scripts#

This document provides instructions on setting up Unity and IDEs for debugging C# Unity scripts.

Table of Contents

Debugging Unity scripts using VS Code (Ubuntu) top#

Setup top#

  1. Install Mono using instruction from official website.

  2. Run dotnet --info and msbuild -version commands in terminal, output should be similar to the picture below (your versions might be different).

  3. Install VS Code.

  4. Install C# and Debugger for Unity extensions in VS Code.

  5. Open up VS Code settings via File menu -> Preferences -> Settings and search for Omnisharp: Use Global Mono and set it to always. Click Restart Omnisharp from the notification that appears at the bottom-right.

  6. In Unity make sure that External Script Editor is set to code.

Debugging top#

  1. In Unity double click on script of interest, VS Code should open it up.

  2. Click Debug view icon on left pane in VS Code.

  3. Select Unity editor in run configurations dropdown. If Unity editor is missing in dropdown, look for errors in log.

  4. Now click Run in VS Code, it should find active instance of Unity, attach to it, debugging starts now.

Note: If clicking Run fails to attach to Unity editor, you can try going View -> Command Palette... -> Unity Attach Debugger and select Unity instance.

If everything is setup correctly you should be able to debug scripts, use IntelliSense and code highlights.

Debugging Unity using Visual Studio (Windows) top#

Setup top#

  1. Install Visual Studio (free Community Edition works fine), don't forget to select Game development with Unity installation option.

  2. In Unity make sure that External Script Editor is set to Visual Studio.

Debugging top#

  1. In Unity double click on script of interest, Visual Studio should open it up.

  2. Click Run (it should say Attach to Unity near green play icon).

Now you should be able to use full Visual Studio C# development functionality.