Does Unity 3.2 support attaching the debugger to an external managed dll?

Having all your C# game scripts in a single DLL for a specific game project makes it hard to share code between projects. It is possible to place code in external DLLs and access these from your scripts, but you immediately lose the ability to debug these classes. Using monodevelop to attach to the unity process only works when you debug your game dll. Why does this not work for external DLLs? Is there a workaround?

Unfortunately Visual Studio does not support debugging Unity projects for the moment. However, since Unity 3.2 one can attach to the running Unity process from MonoDevelop. This does not have to be from your Unity solution, but from any external dll project that is being used in your solution.

The trick is to create an mdb file for the external assembly and place it in the same folder as the dll that you import into your assembly.

"C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0\pdb2mdb.exe" extlib.dll

1.)Set the output path of the mono external dll project to be somewhere in your asset folder. As a post build step, you can run pdb2mdb.exe to create the mdb file in the same folder.

2.)Attach to the Unity process.

3.)Set a breakpoint anywhere you like

4.) Now exercise the code by running your scene in the Unity Editor.

It should break in the external dll.

Some additional info:

For those having problems generating mdb’s of the dll’s:

  • The DLL may not use “yield return” otherwise pdb2mdb will give an error or even crash.
  • .NET Framwork 4.0 is not supported. (3.5. works)

Tested it with unity 3.4.