- Home /
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.
Answer by jorjdboss · Aug 27, 2016 at 03:21 PM
With VS tools 2.2 or higher installed and Unity 5.2 or higher, VS 2015 should work. Try these:
Toggle development build. Once you re-open VS, it should show 'Attach to Unity' for the debug button (F5)
Make sure VS2015 is selected in Unity's preferences and Editor attaching is checked.
Make sure your firewall is not blocking it
Answer by BranchOffGameStudio · Jul 02, 2017 at 11:48 PM
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.
Answer by aeldron · Sep 05, 2019 at 11:26 AM
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.
How you found this solution? Strange that unity doesn't provide it properly in documentation
Answer by LivioDeLaCruz · Aug 23, 2016 at 09:17 PM
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.