Debug Unity using  Visual Studio and VS-Code

Camilo Diaz

Introduction

If you are on Windows or Mac there is an efficient way to debug your code at runtime and set break points in the source code, watch local variables and check the stack trace using vs-code and visual studio.

2. In your visual studio installation make sure you have the Unity Dev-Tools is installed.



3. Go to your unity scene ( you might have to restart the app after installing the mentioned packages ) and select any script you want to debug, if you double click it, visual studio will open the .cs script.  Make sure Visual studio is the predefined text editor

4. Once you are in visual studio, place a break point any where in the source code and press the Attach to Unity button

5. Go to Unity and run the scene that contains the script you opened on visual studio. When the application reach the break point you will notice that Unity stops the scene execution. That is because the Visual Studio debugger took control of the application. Go to visual studio and you will see the break point line executed.

VS-CODE

Please follow the official instructions given in this link