How to attach the debugger to an Editor Script?

I can successfully get Visual Studio to attach to Unity and debug normal C# Scripts, but I don’t know how to get it to debug my Editor Scripts.

I know Visual Studio creates a separate “project” for everything in an /Editor/ folder and compiles them separately, but I can’t seem to figure out how to get the debugger to attach to that particular set of code as it runs in the Unity Editor. Not even sure if this is possible.

With VS tools 2.2 or higher installed and Unity 5.2 or higher, VS 2015 should work. Try these:

  1. Toggle development build. Once you re-open VS, it should show ‘Attach to Unity’ for the debug button (F5)
  2. Make sure VS2015 is selected in Unity’s preferences and Editor attaching is checked.
  3. Make sure your firewall is not blocking it
  4. c# - Visual Studio 2015 for Unity3D Error "Incompatible Project" - Stack Overflow

In order to debug a custom editor or window in VS 2015 do the following:

  1. Click “Attach to Unity” (Assuming you have the VS Unity tools plugin)
  2. Set a breakpoint somewhere in OnInspectorGUI()
  3. Go into the Unity editor and click on the window or editor that you want to debug. Your code should be stopped at your breakpoint in VS since OnInspectorGUI runs similar to the Update function.

In case someone is still looking for this answer:

We can set a system environment variable:
UNITY_GIVE_CHANCE_TO_ATTACH_DEBUGGER = 1

With this, you will be prompted to attach a native debugger when you open the Unity Editor. This will allow you to add breakpoints to editor scripts that run at Unity startup.

Looks like you have to run the game in order for the debugger to pick it up, which is a little unintuitive considering that Editor Scripts do run while the game isn’t running.