Gain +10 Debugging for Unity with Visual Studio

Avatar

John

So you’re ready to level up your debugging skills with Unity and Visual Studio? Check out our new video series in this playlist: Beginner Series: Intro to Visual Studio Tooling for Unity. 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’ll have several techniques in your toolbelt for tackling challenging bugs.

Hunt down that bug

The Unity Console is showing an error and you’re not sure where to start. You could start sprinkling Debug.Log 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.

Understand changing data in your game

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’s behaving as expected. Maybe that method for calculating player health isn’t doing exactly what you thought it was…

Explore and test with live data

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 Debug.Log 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.

Pause at the right time

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’s health is below a certain value because that’s 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.

Fix issues on devices

It’s 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’s running on your desktop or other device.

New experience gained!

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’re just getting started, we also recommend visiting our documentation on Visual Studio Tools for Unity. 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 Developer Community for existing issues and suggestions to upvote what’s important to you.

1 comment

Leave a comment

  • Avatar
    Piotr Karczmarz

    I’ve worked with Unity IDE through the years to on various mobile projects and I was always counting down the time when I would finally be able switch to Visual Studio. It was always a breeze of fresh air and instant productivity boost. Unity devs could make they life so much easier and enjoyable by using Visual Studio more. I’ve used VS professionally for more than 16 years and still Visual Studio rocks! With upcoming 64-bit VS 2022 it will eat alternative IDEs for breakfast.


    Piotr Karczmarz, CTO at ContextKeeper.io, building VS plugin allowing to instant jump to deep work via “mental snapshots”.