{"id":233116,"date":"2021-06-28T06:26:40","date_gmt":"2021-06-28T13:26:40","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=233116"},"modified":"2021-06-28T06:26:40","modified_gmt":"2021-06-28T13:26:40","slug":"gain-10-debugging-for-unity-with-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/gain-10-debugging-for-unity-with-visual-studio\/","title":{"rendered":"Gain +10 Debugging for Unity with Visual Studio"},"content":{"rendered":"<p>So you\u2019re ready to level up your debugging skills with Unity and Visual Studio? Check out our new video series in this playlist: <a href=\"https:\/\/www.youtube.com\/playlist?list=PLReL099Y5nRdW8KEd59B5KkGeqWFao34n\">Beginner Series: Intro to Visual Studio Tooling for Unity<\/a>. This series focuses on common Unity troubleshooting scenarios and how you can use Visual Studio to find and fix them. Each video starts by highlighting an example problem, how you might solve it today, and then shows how to use Visual Studio and the debugger to solve it. By the end of the series, you\u2019ll have several techniques in your toolbelt for tackling challenging bugs.<\/p>\n<h2>Hunt down that bug<\/h2>\n<p>The Unity Console is showing an error and you\u2019re not sure where to start. You <em>could<\/em> start sprinkling <code>Debug.Log<\/code> statements everywhere to narrow it down. However, follow this video to learn how a few basic features of the Visual Studio debugger can save you time. Learn about breakpoints and how they can help you target in on a specific line of faulty code.<\/p>\n<p><iframe title=\"YouTube video player\" src=\"\/\/www.youtube.com\/embed\/wITMFh3KJdE?list=PLReL099Y5nRdW8KEd59B5KkGeqWFao34n\" width=\"879\" height=\"494\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h2>Understand changing data in your game<\/h2>\n<p>Next, the series walks you through how to use the debugger to inspect variables and data in your game. These tools are helpful to understand how code is working so you can verify if it\u2019s behaving as expected. Maybe that method for calculating player health isn\u2019t doing exactly what you thought it was\u2026<\/p>\n<p><iframe title=\"YouTube video player\" src=\"\/\/www.youtube.com\/embed\/_KZIFB2uS2E?list=PLReL099Y5nRdW8KEd59B5KkGeqWFao34n\" width=\"879\" height=\"494\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h2>Explore and test with live data<\/h2>\n<p>You placed breakpoints and inspected variables. Everything looks right! And still the bug persists. You could edit the code, press Play in the Unity Editor, read a <code>Debug.Log<\/code> statement and repeat. This video shows you how to save time by testing different values for a variable and watching how code responds in real-time.<\/p>\n<p><iframe title=\"YouTube video player\" src=\"\/\/www.youtube.com\/embed\/HZOARtIUPvw?list=PLReL099Y5nRdW8KEd59B5KkGeqWFao34n\" width=\"879\" height=\"494\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h2>Pause at the right time<\/h2>\n<p>In the first video, we learned about using breakpoints to stop execution when a line of code runs. However, you might find it unhelpful to stop every time that line of code runs. Instead, you may want to stop when a player&#8217;s health is below a certain value because that\u2019s when you noticed the bug. This video dives into Conditional Breakpoints and how to use them to pause on a line of code at just the right time.<\/p>\n<p><iframe title=\"YouTube video player\" src=\"\/\/www.youtube.com\/embed\/WIqIT1yzkzA?list=PLReL099Y5nRdW8KEd59B5KkGeqWFao34n\" width=\"879\" height=\"494\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h2>Fix issues on devices<\/h2>\n<p>It\u2019s frustrating when your game works fine in the Unity Editor, but then you build and run on a device and there is bug. This video combines everything learned so far to show you how to use how Visual Studio to debug a Unity game that\u2019s running on your desktop or other device.<\/p>\n<p><iframe title=\"YouTube video player\" src=\"\/\/www.youtube.com\/embed\/AuDkiGasy_0?list=PLReL099Y5nRdW8KEd59B5KkGeqWFao34n\" width=\"879\" height=\"494\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h2>New experience gained!<\/h2>\n<p>Congratulations, you earned +10 to your Debugging attribute! You explored Visual Studio debugger features like breakpoints, watches, data inspections and more to troubleshoot Unity games. These tools will save time and frustration when fixing bugs or tuning behavior in your games. If you\u2019re just getting started, we also recommend visiting <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/gamedev\/unity\/get-started\/visual-studio-tools-for-unity\">our documentation on Visual Studio Tools for Unity<\/a>. As always, we love feedback. You can Suggest a Feature or Report a Problem directly from Visual Studio and Visual Studio for Mac from the Help menu. Visit <a href=\"https:\/\/developercommunity.visualstudio.com\/\">Developer Community<\/a> for existing issues and suggestions to upvote what\u2019s important to you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you\u2019re like me, you\u2019ve probably searched through Debug.Log messages in the Unity console to find or fix a bug. Have you also asked if there was a better way? Follow along with our new video series and by the end we think you\u2019ll be surprised at how a few simple debugging tools in Visual Studio can transform your workflow with Unity.<\/p>\n","protected":false},"author":557,"featured_media":233118,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"video","meta":{"_acf_changed":false,"footnotes":""},"categories":[472,155],"tags":[1665,182,12],"class_list":["post-233116","post","type-post","status-publish","format-video","has-post-thumbnail","hentry","category-gaming","category-visual-studio","tag-debugging","tag-unity","tag-visual-studio","post_format-post-format-video"],"acf":[],"blog_post_summary":"<p>If you\u2019re like me, you\u2019ve probably searched through Debug.Log messages in the Unity console to find or fix a bug. Have you also asked if there was a better way? Follow along with our new video series and by the end we think you\u2019ll be surprised at how a few simple debugging tools in Visual Studio can transform your workflow with Unity.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/233116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/557"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=233116"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/233116\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/233118"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=233116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=233116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=233116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}