Skip to content

C sharp in Godot

  • Follow these instructions and don’t forget to enable auto-reload:
  • Pasted image 20231227101015.png
  • To set up debugging, follow these instructions
    • Make sure you put those JSON files in a .vscode folder
    • If it says it can’t find the program (which refers to Godot), then make sure you set an environment variable in your shell file and that you reloaded it.
    • If you get an issue like No loader found for resource: res://NameOfScript.cs , it could be that the environment variable you set was for Godot rather than Godot_mono. Godot_mono is needed to be able to interpret C#.
  • To install packages with NuGet, you just need to run something like dotnet add package TwitchLib from the directory with your .csproj file.
  • To use secrets for your project (e.g. for any API/chat connections), do the following from your project directory:
    Terminal window
    dotnet user-secrets init
    dotnet user-secrets set fake-password hunter2
    • This puts your secret into ls ~/.microsoft/usersecrets/ with the UUID that printed from the init command.
    • To read the secrets, you’ll need to run dotnet add package Microsoft.Extensions.Configuration.UserSecrets and then do something like this from the code:
    using Microsoft.Extensions.Configuration;
    var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
    string username = config["username"];
    string password = config["password"];
  • Prefer the C# collections where you can since they don’t require marshaling to C++ like the Godot collections do. See this for more information.