You can use a debugger to inspect your source code while your application is running. Each supported IDE has dependencies you must install to enable the IDE to integrate properly with Unity. For details of what’s required to configure each supported IDE for debugging in Unity, refer to Integrated development environment (IDE) support.
Although these IDEs vary slightly in the debugging features they support, they all provide basic functionality such as break points, single stepping, and variable inspection. You can attach your IDE to the Unity Editor or Unity Player to debug your code.
Managed code debugging in Unity works on all platforms except Web. It works with both the MonoA scripting backend used in Unity. More info
See in Glossary and IL2CPPA Unity-developed scripting back-end which you can use as an alternative to Mono when building projects for some platforms. More info
See in Glossary scripting backendsA framework that powers scripting in Unity. Unity supports three different scripting backends depending on target platform: Mono, .NET and IL2CPP. Universal Windows Platform, however, supports only two: .NET and IL2CPP. More info
See in Glossary.
To debug your Edit mode or Play mode code as it runs in the Editor:
Tip: When running the Editor in batch mode, you can use the command-line argument -wait-for-managed-debugger
to make the Editor wait for a managed debugger to attach before launching.
To debug your Play mode code as it runs in a Unity Player:
Note: When running the Player in batch mode, you can use the command-line argument -wait-for-managed-debugger
to make the Player wait for a managed debugger to attach before launching.
The Editor’s code optimization setting has two modes:
To attach a debugger to your Editor, you first need to set the Editor’s code optimization mode to debug mode. You can change the code optimization setting in the following ways:
-releaseCodeOptimization
to start the Editor in release mode and -debugCodeOptimization
to start it in debug mode. For more information, refer to Debugging arguments.Breakpoints allow you to specify points in your code where you want to pause its execution. In your IDE, you can set a breakpoint on a line of code where you want the debugger to stop. While the IDE is at a breakpoint, you can view the contents of variables step by step.
If you attach your IDE to the Unity Editor, the Editor becomes unresponsive at breakpoints until you choose the continue option in your IDE, or stop debugging.
For more information of how to set breakpoints, refer to the relevant documentation for your IDE:
How you attach your IDE to the Unity Editor or Player process is specific to the IDE you use. Some IDEs have a Unity-specific attach option that differs from the standard process for attaching to other applications.
For information on how to attach to Unity for debugging, refer to the relevant documentation for your IDE:
Once you’ve attached to the Unity Editor, return to the Unity Editor and enter Play mode to start debugging.
To attach to the built Player, select the IP address (or machine name) and port of your Player from your IDE. When you’ve attached the debugger, you can begin debugging normally.
Note: Your IDE displays all instances of Unity that are available to debug. Make sure you distinguish the Editor process from the Player process if both are running.
To debug a Unity Player running on an Android device, connect to the device using USB or TCP. For example, to connect to an Android device in Visual Studio, select Debug > Attach Unity Debugger option. A list of devices running a Player instance appears.
For more information, refer to Debug on Android devices.
To debug a Unity Player running on an iOS device, connect to the device using TCP.
Ensure that the device only has one active network interface (Wi-Fi recommended, turn off cellular data) and that there is no firewall between the IDE and the device blocking the TCP port (port number 56000 in the above screenshot).
Important: iOS doesn’t support debugging over USB.
For more information, refer to Test and debug an iOS application.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.