10 ways to speed up your programming workflows in Unity with Visual Studio 2019

Visual Studio 2019 offers world-class debugging, and lots of new tools and customization options so that you can set up your coding environment exactly the way you want it. It also comes with a range of powerful features for working with C# in Unity that helps you write and refactor code quicker than before. In this blog post, we will take a look at 10 tips on some of these features which may speed up your workflow too.

Our Unity evangelist Arturo Nereu and Abdullah Hamed, program manager for Visual Studio Tools for Unity at Microsoft, recently hosted a Unite Now session sharing tips and tricks on how to get the most out of Visual Studio 2019 when developing in Unity.

This post shows a quick overview of some of these tips. We also added links directly to those sections from the talk as well as other related content, if you want to dig deeper.

Tip 1: Attach the Debugger to Unity and Play

Using Console.Log is an easy and quick way to help debug your project utilizing Unity’s console view. However, Visual Studio offers a more efficient way which becomes increasingly valuable as your project gets more complex. In Visual Studio, simply click the Attach to Unity button in the Visual Studio menu. This creates a connection between the two applications so that you can insert breakpoints and step through your code, while being in Play mode in Unity. You can also click Attach to Unity and play to start the execution without leaving your IDE. The beauty here is that it allows you to inspect the state of your code flow and values of the properties etc. at runtime. While this may seem trivial, being able to pause the execution at any time during gameplay and step through to inspect the specific state of the game and values of your properties in that exact frame, is a very powerful tool when debugging. 

Another handy option when working with breakpoints is that you can insert your own conditions with related actions such as a conditional expression which has to evaluate as true before applying in your debug flow. 

Tip 2: Get performance insights and suggestions for best practices

Visual Studio 2019 introduces Unity Analyzers. An analyzer works by detecting a code pattern and can offer to replace it with a more recommended pattern. Unity Analyzers are a collection of Unity-specific code diagnostics and code fixes that are open source and available on GitHub. Analyzers can provide you with a better understanding of Unity-specific diagnostics or simply help your project by removing general C# diagnostics that don’t apply to Unity projects. An example could be a simple conditional statement where you need to check if the GameObject has a specific tag to apply a certain behavior to it.

if(collision.gameObject.tag == “enemy”) { // Logic being applied to enemy GO }

if(collision.gameObject.tag == “enemy”)

{

// Logic being applied to enemy GO

}

The analyzer would be able to analyze your code, will detect the pattern and offer to use the more optimized method instead. In this case, the analyzer would suggest the CompareTag method which is more efficient.

if(collision.gameObject.CompareTag == “enemy”)

Continue reading

This post was originally published on this site