Search Unity

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

, julho 14, 2020

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.

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.

While the above example represents a minor optimization tweak with no significant impact in a single script attached to a single GameObject, this may be different for a large scale project with 1000s of GameObjects with the script attached. It’s the sum of all parts when looking into performance optimization and Analyzers can make it easy to help you identify and improve your performance simply by reducing the unneeded overhead by optimizing the code syntax. 

You can also find a list of the analyzers here and if you are interested in learning more visit this blog post or jump directly to this part of the Unite Now talk

Tip 3: Use the Task List as a followup checklist 

A common challenge when creating your scripts is the need to come back at a later point and revisit the code. That might be a result of implementing code snippets which eventually will need refactoring for better performance later but serves the current needs as you are f.x. testing out game mechanics. Visual Studio has a handy feature to keep track of this called Task List which allows you to track code comments that use tokens such as TODO and HACK, or even custom tokens. You can also manage shortcuts that take you directly to a predefined location in code. To create a task for later simply add the token in your code: 

The Task List window, which you can access from under View in the menu, gives you an overview of all the tasks you tagged and links you to those specific parts of the code in just one click.  

Adding a comment followed by the // TODO: in your code makes it easy to “tag” action items you want to follow up on at a later point using the Task List window as shown in the above on the right-hand side.

As the list of action items in your project grows, you can even configure your own custom tokens in the task list and assign priorities and organizing for your refactoring process effectively. To customize your Task List tokens: go to Tools > Options.


See the full example in the
Unite Now session here.

Tip 4: Use snippets to speed up your workflows

Code snippets are small blocks of reusable code that can be inserted in a code file using a right-click menu (context menu) command or a combination of hotkeys. They typically contain commonly used code blocks such as try-finally or if-else blocks, but you can also use them to insert entire classes or methods. In short, they offer you a handy way to save a lot of time by creating the boilerplate code for you.

To surround your code with a snippet such as a namespace or region, press CTRL + K + S. That allows you to apply the snippet as demonstrated in the video below:


You can find a step-by-step walkthrough of creating your own code snippets in Microsoft’s documentation (
Visual Studio, Visual Studio for Mac).

Tip 5: Rename all variables in just a few clicks

A common workflow when you are refactoring your code is renaming your variables to more descriptive and accurate names. Changing it one place obviously means you also have to fix all references to that variable. However, Visual Studio offers an easy shortcut to do this in one operation. Simply highlight the name of the variable you want to rename and right-click (or use the keyboard shortcut CTRL + R) and then rename the variable. Select preview changes to review the implications of the change before applying.


You can use the same tip for changing the classes of your script but remember you have to rename the C# file accordingly to avoid the compilation errors. Learn more about the class renaming flow
this part of the Unite Now session.

Tip 6: Comment out your code with a keyboard shortcut

Commenting or uncommenting blocks of code is another common workflow when refactoring or debugging your code. It can be a time-consuming task when you do it one line at the time. Visual Studio, however, allows you to comment out entire blocks of code using a simple shortcut command: Ctrl+K+C and Ctrl+K+U for uncommenting it again. If you are on Mac, simply use CMD+K+C to comment out and CMD+K+U to remove the comments again.


Being able to comment out entire blocks quickly can be an efficient way to suppress specific game logic during your testing workflows.

Tip 7: Set up integration with GitHub in a few clicks

While Unity Collaborate makes it easy to save, share, and sync your project with others directly from Unity with a user-friendly visual interface, some teams and developers prefer using source control solutions such as GitHub. Working with GitHub for source control is now much easier with the Github for Unity plugin. The extension is completely open source and it allows you to view your project history, experiment in branches, craft a commit from your changes, and push your code to GitHub without leaving Unity. The GitHub authentication is embedded in Unity, including 2FA and with a click of a button, you can quickly initialize your game’s repository without having to use command-line instructions. It allows you to create a Unity specific .gitignore file so you don’t have to set it up manually. With Visual Studio 2019 also comes a new interface which makes it even easier to work with GitHub directly in the IDE.


To activate the new interface in Visual Studio: Go to
Tools > Options > Environment > Preview features > New Git user experience.

You can also follow along with the video instructions from the Unite Now session, which shows a more in-depth walkthrough of getting started.

Tip 8: Collaborate remotely in real-time with Live Share

Live Share enables you to share your instance of Visual Studio directly with your teammate using just a link, allowing them to edit your code and collaborate on your project in real-time. You don’t have to clone a repo or set up the environment first in order to do the sharing. You both just need to have Visual Studio installed and then it’s as easy as clicking a button to create the Live Share session. 

Visual Studio Live Share allows you to share your Visual Studio session and collaborate with others directly on the code in real time.

To get started simply select Live Share to generate a link to the parts of your code that you want to share with anyone that has Visual Studio or Visual Studio Code installed. A sharing session is created between you and your collaborators, allowing them to see your code without having to install anything except for the editor. It works almost instantly. 

You can learn more about Live Share from our Unite Session here, visit the Visual Studio product page or jump directly to the Quickstart guide here.

Tip 9: Create boilerplate code easily for Unity Messages

Remembering the signature of all the MonoBehaviour methods is tricky and while the Unity documentation will have you covered, Visual Studio provides a neat feature that allows you to look it up directly in the IDE. Simply click CTRL + Shift + M, search for the function you would like to implement, and filter through the search result to find the method. Select the checkbox and click Ok to insert the boilerplate code for the method directly in your code ready for you to use.

Tip 10: Keyboard shortcuts

Several of the above tips are available with handy shortcuts and at the end of the day, knowing those shortcuts may be the biggest timesaver of them all. So let’s wrap up the list with a summary of the keyboard shortcuts to these tips and a few more as a bonus.

What Windows Mac
Search your entire project for anything. Use CTRL+T  CMD + .
Implement Unity Messages CTRL + Shift + M  CMD + Shift + M 
Comment out code blocks CTRL + K  / CTRL + C CMD + /
Uncomment blocks of code CTRL + K  / CTRL + U  CMD + /
Copy from clipboard history CTRL + Shift + V
View task list CTRL + T No default keybinding, but you can bind it.
Insert a surrounding snippet such as namespace CTRL + K + S: No default keybinding, but you can bind it.
Renaming a variable while updating all references CTRL + R CMD +R
Compile the code  CTRL+SHIFT+B  CMD + Shift + B

Share your tips?

Visual Studio 2019 is packaged with features and there are so many customization options that can enhance your productivity working with Unity depending on your specific workflows. There’s too many to cover them all here. We hope that the few tips that we shared here will inspire you to dive in and that you’re finding the format useful. Let us know if you have any tips we didn’t cover, and feel free to share them with the community in the comments. We’d also love to hear if you would like more tips and tricks on how to improve your workflows in Unity and if there are any topics, in particular, that you would like to have covered in a future blog post.

Got feedback on how Visual Studio could be improved?

We are constantly working on improving the workflows and our teams are working closely with Microsoft in terms of giving you the best IDE experience. Hence we would love to hear from you if you have any ideas or feedback. Feel free to ping John Miller at @jmillerdev, Senior Program Manager, Visual Studio Tools for Unity at Microsoft, or share your feedback with us in our Scripting forum.

28 replies on “10 ways to speed up your programming workflows in Unity with Visual Studio 2019”

The shortcut for renaming a variable (on Windows) is CTRL + R / R. The first key combination is for accessing the Refactor mode.

Visual Studio can now be used for diff/merge! In preferences, external tools just set the diff/merge tool to custom tool and set the path to devenv.exe. In the two way, 3way and merge set the parms.

JetBrains (and the ReSharper plugin for Visual Studio) has so much possibility of options customization for code layouts, ad refactoring hints. Unfortunately, it’s not affordable for everyone.

I really love Unity, and I quite like Visual Studio and Github, but I must say: Please don’t recommend Github for Unity. It has lots of bugs, it doesn’t have anyone actively maintaining it, it hasn’t had a release in over a year. It’s so ridden with bugs that sometimes it’s even scary to use it. Instead of making users life easier, it ends up making it hard. Right now, I’ve just found it thousands of times better to just use git and git-lfs normally, and though I wish I had a friendlier option, I’d much rather have some tutorials on how to use tech that works, than being officially pointed to use abandonware.

I understand that there is a Git for Unity package (https://github.com/Unity-Technologies/Git-for-Unity) that might fill a lot of the git-shaped hole in Unity, if not now, in the future. It’d be awesome to have some information about its status. There’s some basic but useful documentation for this package on Github, but I can’t found documentation in Unity’s sites. I can’t find any official mention of it. It’s kind of confusing to be recommended a buggy, abandoned, solution instead of the existing project in progress at Unity. It makes me wonder if Unity’s own Git project has been abandoned, or if it’s still planned to be released out of preview.

I agree and recommend GitHub Desktop instead. It’s outside Unity (so no slowdowns) and can be used on other projects (not just unity) by both artists and newer programmers. I’ve been very happy with it for the few years I’ve used it now and it has active development so you have no fear of the future with it.

https://desktop.github.com/

True. Last time i used Github for Unity is with Unity 2019.4 but it seems not working as it should be.

Yes, I tried to set up GitHub for Unity and couldn’t get it to work. Authentication wouldn’t succeed no matter what I tried. The interface looked pretty unpolished as well, compared to SourceTree and Github Desktop.

I absolutely agree. Having a git tool embedded within Unity, while sounding good on paper, works terribly in practice. Doing small things, sure – but actually managing your project with it? I can’t imagine even trying. With an external client, you can push and pull and do whatever you need to do without fearing recompiling or reloading or anything. Things can seriously get messed up otherwise.

I HIGHLY recommend the Fork client (https://git-fork.com/), the free version is free forever, and it’s by far the most stable and reliable client I’ve ever used.

Tip for Unity for XboxOne:
– Do not install Visual Studio 2019. XboxOne development supports only Visual Studio 2017 and older, but Unity automatically gets newest Visual Studio for compilation so when you install Visual Studio 2019 you cannot compile for XboxOne (even if you have also installed Visual Studio 2017). You cannot change it anywhere in project. It is builtin Unity “feature”.

That was the case for the early days of Xbox One development. I think this might have changed.

Great advice.

Too bad I can’t use VS2019 because Microsoft account management is too much of a nightmare.

Tip 11
Use visual studio code…
Much faster, much more convenient, way better keyboard shortcuts.
Perfect for unity!

UsE vIsUaL sTuDiO cOdE.

I prefer the key bindings in VS 2019 so your point about them being “better” in code is just your opinion.

1. Ctrl + , brings up the “Go To” panel for looking up files, types, members, etc.
2. F12 while the cursor is over an item, goes to definition, Ctrl+F12 goes to implementation (Ctrl + F12 is for methods that are defined in an interface and implemented in a class).
3. While debugging in VS 2019, debug panels “watch”, “auto”, and “locals” let you search in object trees to find the current value for looked-up items.
4. If you don’t know where a certain item is located in VS, press Ctrl + Q and start typing, and VS shows a list of matched items with their keyboard shortcut.
5. View > Other Windows > C# interactive is a scratch pad that you can write some C# code and see the immediate result, without the need to put a breakpoint, etc.

In tip 2 there is a mistake.

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

instead of

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

Great post. There is a small problem with CompareTag code snippet, it should be if(collision.gameObject.CompareTag("enemy"))

Comments are closed.