After the first episode in which we talked about why use Godot and why C#, now we will proceed to install and configure a comfortable and functional development environment, these are the various steps that we must follow:

  1. Install the SDKs
  2. Install VSCode
  3. Install Godot
  4. Let’s test it all: Hello World!

1. Install the SDKs

First, download the Visual Studio Build Tools if we use Windows or the Mono SDK if we use Linux or macOS, and proceed with their installation. With Linux or macOS, we need to install the Mono SDK, following the tiny guide directly from the download page. For Windows, however, things will be a little more complicated, so I’ll show you below.

Visual Studio Build Tools installation

Once the installation of the Visual Studio Build Tools has started, let’s move to the tab “Single components”* and select the following items:

  • .NET Core SDK (we will need it to use some VSCode extensions and features)
  • .NET Framework 4.7 Targeting Pack (used to build Godot games)
  • .NET Core Runtime (will be automatically selected by the .NET Core SDK, if not, activate it ourselves)

After this proceed with the installation and the add of the following path to the Windows:

Visual Studio Build Tools
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"

2. Install Visual Studio Code

Before proceeding to the second step, I recommend restarting the PC, to apply the changes to the system path.

Download and install Visual Studio Code, it’s free, it’s open-source, it’s cross-platform, and it’s incredibly customizable. I recommend it for the integration that we can achieve with Godot and with the extensions for C#.

Once Visual Studio Code has started, install the following extensions:

3. Let’s install Godot

Download and extract in a folder of our choice, the latest version of Godot Mono.

Once this is done, let’s start a new project and proceed with its configuration.

Godot New Project

Now change the following settings:

  • Editor -> Editor Settings
  • General -> Mono -> Builds -> Build Tool: MSBuild (VS Build Tools) if on Windows or MSBuild (Mono) for other platforms.
  • General -> Mono -> Editor -> External Editor: Visual Studio Code

Now let’s proceed with the configuration of the newly created project, this configuration is to be done every time you create a new project:

Download the following package: MonoDebuggerQM

Inside the project root, create a folder called “addons” and extract the contents of MonoDebuggerQM inside it. Now going in the Project menu -> Project Settings -> Plugins activate it by changing the state of the plugin to active.

After doing this in the upper right corner of the Godot interface, we will see the following menu:

MonoDebuggerQM

By checking the item, we can quickly enable or disable the ability to wait for debugging when we start it through VSCode, for now, let’s stay unchecked.

4. Hello World!

Let’s now create our first C# script:

  • Create Root Node -> 2D Scene
  • Click F5
  • Confirm and save, check that the compilation is successful. If successful, we will see a gray window, close it.
  • Let’s make it the default scene by pressing the F5 key again and select it.
  • Right-click on Node2D -> Attach Script: Select Language: C#
  • Click on Create

If we have configured everything correctly, Visual Studio Code will automatically open. Let’s now configure the Launch or Debug functions directed by VSCode(these two files are to be added in each new project):

  • Run -> Add Configuration …
  • Select C# Mono and modify the content in the following way
  • Replace ** PATH **
  • For Windows: Path of the Godot executable
  • For Linux/macOS: Path towards Godot-mono
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "**PATH**",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": "Attach",
"type": "mono",
"request": "attach",
"address": "localhost",
"port": 23685
}
],
"compounds": [
{
"name": "Launch & Attach",
"configurations": [
"Attach",
"Launch",
]
}
]
}

In this way, we have added three functions that can be called from the Visual Studio Code debug menu, which will allow us to:

  • Launch: Start the game compilation (remember to disable Wait for the debugger, in this case)
  • Attach: Start the debugger directly from VSCode
  • Launch & Attach: Perform both functions

Now let’s proceed to configure the build tasks:

  • Terminal -> Configure Tasks …
  • Create tasks.json file from template and select MSBuild and finally modify the content as follows
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "msbuild",
"args": [
"/p:Configuration=Tools;Platform=Any CPU;GenerateFullPaths=true"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}

Now let’s go back to Godot and put the check in the Debugger menu -> Wait for the debugger. Let’s check now if we have completed all the configurations correctly.

In the main C# file, in VSCode, add the following code inside the _Ready() function.

string world = "World!";GD.PrintS("Hello", world);

Add a breakpoint by clicking on the margin of the row “GD.PrintS(“Hello”, world);” and start compiling and debugging by selecting “Launch and Attach” in the Visual Studio Code debug menu.

We will then get the following window:

Visual Studio Debug

Everything works as expected!

To stop debugging, click on the red button in the exit bar at the top of the window twice, or Shift + F5 always twice.

That’s all

If you have problems, you can contact me, or download the source code of this project from the following link on Github.

See you!

--

--

Responses (1)