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.
In order to debug a custom editor or window in VS 2015 do the following:
Click “Attach to Unity” (Assuming you have the VS Unity tools plugin)
Set a breakpoint somewhere in OnInspectorGUI()
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.
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.