PinGodGame Projects - Add a C# Script


Create Script for MyScene


This template project will not give any errors if you don’t use a C# script but if using an existing scene that uses a script then we will need to add a C# project to the directory.

As we’ve referenced a C# script from the SwitchOverlay.tscn then we need to make a C# project.

Fortunately that is easy as we just have to make a new script to do this.

  1. Selecting the MyScene node and in the inspector bottom right of the pane is a script section
  2. Add new script here selecting C#

image image

  1. When you click create, a project will be created and open the script in a Godot window

image image


New files


  • Projects-MyProject.csproj
  • Projects-MyProject.sln
  • MyScene.cs

External editors


With the project open in Godot go to:

Editor > Editor Settings > Mono > External Editor


Visual Studio Code


Visual Code is the fastest to open the C# files, if you select from the options and double click MyScript.cs that will open for editing in VsCode.


Visual Studio


Godot CSharp

Debugging

Add the following to the .csproject to launch projects from there but can’t hit breakpoints.

Program C:\Godot\Godot.exe --path C:\Path\To\Godot\Project\
Debugging Extension

Difficult to get working…

An Visual Studio extension can be used for debugging Godot. Download and run the .vsix.


Godot4 better for this as you can use .net6 by default.

Godot 4.x changes to use .NET [Core] Runtime rather than Mono, so you can attach to a running Godot game with the VS debugger.