Unievrsity of Games University of Games

Using Visual Studio in Unity Engine

During game development process in Unity we are writing scripts. For convenience we usually use any integrated development environment (IDE)

Photo by Mohammad Rahmani / Unsplash

Using Visual Studio in Unity Engine

During game development process in Unity we are writing scripts. For convenience we usually use any integrated development environment (IDE). By default Unity provides MonoDevelop IDE. Do game developers have any other options to choice? Yes, they do. They can start using Microsoft’s Visual Studio as an IDE to cope with scripting experience.

How to setup

Currently, the integration of Visual Studio with Unity is easier than ever. You can simply install Visual Studio during Unity installation. In Choose Components section make sure that Microsoft Visual Studio Community 2017 option is checked.

After installation, all C# scripts should open in Visual Studio. However if they still opening in MonoDevelop, you should setup Visual Studio manually. Go to Edit/Preferences/External Tools then from External Script Editor choose Visual Studio 2017 option.

Now you can start work with Visual Studio IDE.

License and pricing

The Unity provides free Community version of Visual Studio. Any individual developer can use this version to create their own free or paid apps. Community version can also be used:

  • in classroom learning environment
  • for academic researches
  • for contributing to open source projects
  • or even in non-enterprise organizations, up to five users.

Beyond that, company have to buy one of following license:

  • Professional — for smaller teams ($539/yr or $45/mo — per user)
  • Enterprise — for enterprise organizations ($2,999/yr or $250/mo — per user)

Visual Studio Tools for Unity

Visual Studio Tools for Unity (VSTU) is a special plugin which enchances your productivity. It provides features which make work with code more easier. Visual Studio 2017 includes VSTU built-in so we don’t have to install any extra plugins.

The most interesting features provided by VSTU:

  • the Unity Project Explorer which displays Unity project in the same way like in the Unity editor
  • Unity console integration — you can check Unity console output without leaving Visual Studio
  • Syntax coloring for the Unity’s ShaderLab language — easier shaders writing
  • Unity behaviours browser — press CTRL + SHIFT + M to select methods to insert from list.
  • MonoBehaviour wizard — allows to quick insert Unity’s code templates (e.g. Update() method). Press CTRL + SHIFT + Q
  • Access Unity documentation from Visual Studio — highlight the API call you want to learn about, then press CTRL + ALT + M, CTRL + H
  • and my favourite…

Superior Debugging

Yes, you can debug C# scripts and DLLs regardless of whether it’s running in the Unity editor or standalone. Debugger provides features:

  • breakpoints (including conditional breakpoints)
  • inspection and modification of the values of variables and arguments
  • evaluation of complex expressions in the Watch window
  • ability to dive into complex objects and data structures.

How to run debugger

Firstly you need to attach Unity Debugger. In Visual Studio select Debug/Attach Unity Debugger, then select current Unity instance or input IP to connect remote.

Next click OK and your debugger is ready to go. That’s it. However in purpose to see any effect of debugging you need to add at least one breakpoint in your code. To add breakpoint click on the left side of line that you want to stop execution on it. Red dot should appear.

Now when execution met this line, game will pause and then you can start debugging of your code. By hovering mouse cursor on variable you can inspect it values.

Conclusion

Visual Studio is a powerful masterpiece produced by Microsoft. Integration with Unity is very easy and list of pros is long. From benefits from Visual Studio Tools for Unity, throughout IntelliSense with MonoBehaviour API, integration of version control systems and many, many more. What is more Visual Studio IDE is available for both OSes: Windows and macOS.

If you don’t use Visual Studio, it’s appropriate time to start! It’s really worth it!

To help us create more free stuff, consider leaving a donation through Patreon where you can vote for the next asset pack and get access to future packs & articles earlier. Sharing knowledge is our passion. Unfortunately, keeping a team of professionals costs a lot that’s why we are constantly taking on new opportunities.

​We’ll be publishing any news on the following outlets:

Thanks for reading!

Leszek W. Król

Leszek W. Król

On a daily basis, I accompany companies and institutions in designing strategies and developing new products and services.