Nodachisoft Nodachisoft logo, Katana Sword Icon
  
@Amaji✎ Update December-26-2021

Creating a comfortable development environment with Unity+VSCode

Creating a comfortable development environment with Unity+VSCode

Abstract

This article is my memo for creating a comfortable development environment with Unity + VSCode.

My Enviroments

Softwre Version
Unity Unity2020.3 LTS
OS Windows 10 Home
VSCode 1.63.2

Install Unity and VSCode

For Unity, install the stable version (LTS) unless you have a specific reason not to.

VSCode can also be downloaded and installed from the following link.

It can also be installed from package management tools such as Chocolatey.

Enable Unity to open VSCode by default

Switch the standard editor to "VSCode" when you select a script in Unity or when you open a project.Switch the standard editor to "VSCode".

In Unity, select Edit -> Preferences and press

Set Default Open ide

From the left side of the Preferences window, set External Tools -> External Script Editor to Set it to Visual Studio Code.

externaltools

Open the contents of the Unity project in VSCode.

Open the current Unity project with VSCode. Assets -> Open C# Projec to open it in VS Code.

OpenVSCode

Installing Extension Plug-ins

Unity + VSCode alone is still inconvenient for coding.

To make the development process more efficient, the following extension plug-ins should be installed.

The following are the extension plugins that I installed for VSCode.

Plugin Name Summury
C# for Visual Studio Code It complements C# coding on VSCode.
Debugger for Unity Debuggable with breakpoints, etc. when run in Unity
Unity Code Snippets Frequently used code in Unity can be easily generated with code completion.
c# XML Documentation Comments It completes the description of comments when coding C# on VSCode.

All of them can be installed immediately as plug-ins from "Extensions" of VSCode.

Below is a brief description of the main points of each extension plug-in.

C# for Visual Studio Code

NET Core or Mono, it will be able to support C# coding running on .

NET Core or Mono. You can use Ctrl+Space to complete the following in pre-written code.

completion example in vscode

Using .NET Framework in VSCode Although not directly related to Unity, VSCode is not suitable for development using the old-fashioned Windows Native features . (NET Framework (although it's not impossible). NET Framework, it is better to use Microsoft Visual Studio Community instead of VSCode, as it has better code completion and debugging for related libraries.

Debugger for Unity

It is possible to place breakpoints in the code on VSCode (a useful feature to temporarily stop execution and check the contents of variables, etc.).

BreakPoint

You can put a breakpoint by left-mouse clicking on the left side of where you want to stop in the code.

You can run Unity, stop at the line of the breakpoint, and see what happens to the contents of the variable a.

In order to actually stop at a breakpoint, we need to specify from VSCode which Unity Editor we want to associate with it.

Open the VSCode command palette with Ctrl+Shift+P and select "Unity Attach Debugger".

launch unity attach debugger

If you have more than one Unity Editor running, you will see a selection.

Menu Which unity editor you want to attach

When the debugger is connected to the Unity Editor, the following information for debugging will be displayed on VSCode.

Debug Mode

You can also debug on the Unity side! message will be displayed.

Unity Editor inform that debugger connected to

The actual way to put breakpoints and debug is omitted(maybe another article).

Unity Code Snippets

For Unity related libraries, you will be able to use templating code that need to be created in a standardized way.

For example, if you create a new .cs script and type Mono, "MonoBehaviour" will appear in the code completion list, as shown below.

Mono

If you complete the code in this state, you will see

Codehokan

This is the template for a class that inherits from MonoBehaviour, which is the base class for creating Unity components. which is the base class for creating Unity components (commonly referred to as boilerplate).

In addition to this, you can also use the If you type "Start" in a class that inherits from MonoBehaviour, it will generate the necessary template-like methods as shown below.

Start

You can also use the completion function to generate the code for Unity's log output, which is often used.

Log

c# XML Documentation Comments

When commenting in C# coding, it completes the required template.

For example, if you put the comment "///" just before the definition like this

var

It will automatically generate a comment insertion template as follows.

commentinserted

This is so useful!

It will also generate the necessary comment templates for the methods. If you type "///" just before a code like the following

method

It will also generate templates with arguments and return values as shown below.

methodcommentinserted

TroubleShooting

If the code does not complete properly, please refer to the following article, which may help!

Websites and references that were very helpful.

Page History

date modification
none
 
 
Message sent

Thank you for your message.

Something error has occured!

Sorry. The Error has occurred.We apologize for the inconvenience.Please try again in a few minutes or contact us via DM below.

Twitter:@NodachiSoft_eng
Name:
 
Replay To:
 
Message:
 
Back
Check the content!

Send the following information to us. If you are happy with your submission, please click "Send". If you want to modify it, please click "Back".

Name:
 
Reply To:
 
Message:
 
Enter a confirmation key to make sure that you are not operating from a Robot.
Confirmation Key is 95
Back
 / 
Go to Confirmation
Entry fields
Go to Confirmation

There are 5 articles that may be relevant!

System.Type.GetType returns null in Unity C# code

System.Type.GetType returns null in Unity C# code

#Unity#.net✎ 2022-1-11
System.Type.GetType returns null in Unity C# code
Table Of Contents
Creating a comfortable development environment with Unity+VSCode
Creating a comfortable development environment with Unity+VSCode
Abstract
Abstract
My Enviroments
My Enviroments
Install Unity and VSCode
Install Unity and VSCode
Enable Unity to open VSCode by default
Enable Unity to open VSCode by default
Open the contents of the Unity project in VSCode.
Open the contents of the Unity project in VSCode.
Installing Extension Plug-ins
Installing Extension Plug-ins
C# for Visual Studio Code
C# for Visual Studio Code
Debugger for Unity
Debugger for Unity
Unity Code Snippets
Unity Code Snippets
c# XML Documentation Comments
c# XML Documentation Comments
TroubleShooting
TroubleShooting
Websites and references that were very helpful.
Websites and references that were very helpful.
Page History
Page History
Nodachisoft © 2021