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.
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.
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.
If you were using Unity 2020 and up, Unity might ask you to enable debugging. Select Enable for this session or for all projects.
Visual Studio Unity debugger should start and be ready and attached to Unity.
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.
Please check our full video covering this topic in our video beginner series for Unity.
Top comments (0)