Can Visual Studio be used as a debugger for Unity?

The Unity 3.0 docs mention that Visual Studio can be used for editing code, but for debugging code the only information provided is for MonoDevelop.

Is it possible to use the Visual Studio debugger instead? (perhaps via the Mono Tools for Visual Studio add-in?)

UnityVS, a third party plugin, lets you use Visual Studio as a debugger for Unity.

No. Only MonoDevelop can be used as a line-by-line debugger in Unity 3. MonoDevelop is a .NET-like environment for Windows and OSX.

There is a very high-effort way to get this working, as the wire-protocol that MonoDevelop uses to communicate with the builtin debugger inside Unity is "documented" as the sourcecode that writes/reads to it is opensource. It would be possible to write a Visual Studio plugin that talks Unity in the "debugger language" it understands. This is defenitely not a light undertaking however. (for implementation, see Mono.Debugger.Soft.dll in mono's sourcecode)

It is now possible to debug in Visual Studio. Here’s the link to the Unity website explaining how: Get Started with Visual Studio and Unity - Unity Learn

In short, once you have Visual Studio and Unity Tools https://www.visualstudio.com/en-us/features/unitytools-vs.aspx you can launch your game, open your code in Visual Studio (double-click on a script if Visual Studio is configured to be your code editor) and then click on the “Attach to Unity” button.

I'd been wondering this myself for a while, so after seeing your question I thought I'd have a pop at it...

I just tried building a development exe and setting up the Dev Studio project to run the standalone exe (and use its .pdb) when I debug.

This lets me set breakpoints in VS, but they never get hit (although the code is clearly running).

This was better than I expected, since Unity uses mono rather than the .net framework I didn't even expect the .pdb format to necessarily work for VS.

Have just started messing about with the mono tools for Visual Studio. will post back if I have any joy (don't get your hopes up!).

darbotron

with the mono tools and a modified version / adopted version of the u3 monodevelop plugin it could work.

but the mono tools for vs are a heck expensive so actually using monodevelop and report the bugs so it can be pushed forward has a much stronger longterm benefit

I had a look at UnityVS and did a post: http://azuregames.azurewebsites.net/2013/11/18/unity-and-unityvs/

Definitely worth $100 to me.

UnityVS developers SyntaxTree have just been acquired by Microsoft. You can now use Visual Studio Tools for Unity for free!

Now, there is a tool for VS:
http://unityvs.com/news/2014/07/29/visual-studio-tools-for-unity-1-9/

It was not free, but Microsoft buyed the SyntaxTree company and it’s now a free tool!!!

Enjoy

Visual Studio Community Edition is now free. Visual Studio Tools for Unity is now free. Use both, debug with Visual Studio - for free :slight_smile:

Yes. Here are the instructions. It may not work for Unity 5 though.

With Unity 3.2 this feature now exists.

You have to debug using the MonoDevelop that ships with Unity 3.2.

When you have the project open in MD, click Run > Attach to Process. Then choose the Unity editor process or your running built debug exe. If you attach to the editor, you can start and stop the game editor at any time using the "play" button or Ctrl+P.

i have visual c# (free download from microsoft) and use that to write my unity scripts it has a good debugging system

but...you have to sync the visual studio project (only one click from within unity)

and a lot of the time i find i have to translate code from java to c# which can be a bore