DEV Community

Cover image for Unity 105: Debugging and Analyzing
Abdullah Hamed for .NET

Posted on

Unity 105: Debugging and Analyzing

Visual Studio IDE supports debugging Unity projects. On windows you can add Unity support from the Visual Studio installer by modifying your installation. Unity support is built-in into Visual Studio for Mac, and you do not need to modify your installation.

unity support in Visual Studio installer for windows

Debugging

Debugging enables you to freeze the execution of your script as any point you set using breakpoints. To set a break point, select the area in the margin of Visual Studio IDE next to the line you want the code to freeze at. A red dot should appear on that margin showing that a breakpoint has been set.

a breakpoint with a red dot showing in the margin of visual studio

To start the debugger, you need to have both Visual Studio IDE and Unity running. Select the Attach to Unity button at the top of the Visual Studio IDE.

Attach to Unity button in Visual Studio

If you were using Unity 2020 and up, Unity might ask you to enable debugging. Select Enable for this session or for all projects.

Enable debugging dialogue in Unity 2020 and up

Visual Studio Unity debugger should start and be ready and attached to Unity.
Unity debugger activated in Visual Studio

Now, select the play button in Unity to run your game. One Unity reaches the line of your code, Unity will freeze. You will be able now to look at the debugger locals window and see properties of your code and game objects. You can hover on variables to see their value at that specific state, or you can dig deeper into the locals window at the bottom of the debugger to see them in a list.

Visual Studio IDE with stopping at a Breakpoint

Please check our full video covering this topic in our video beginner series for Unity.

Top comments (0)