Righthand.GodotSourceGenerator 1.1.1-beta.5

Prefix Reserved
This is a prerelease version of Righthand.GodotSourceGenerator.
dotnet add package Righthand.GodotSourceGenerator --version 1.1.1-beta.5
                    
NuGet\Install-Package Righthand.GodotSourceGenerator -Version 1.1.1-beta.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Righthand.GodotSourceGenerator" Version="1.1.1-beta.5">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Righthand.GodotSourceGenerator" Version="1.1.1-beta.5" />
                    
Directory.Packages.props
<PackageReference Include="Righthand.GodotSourceGenerator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Righthand.GodotSourceGenerator --version 1.1.1-beta.5
                    
#r "nuget: Righthand.GodotSourceGenerator, 1.1.1-beta.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Righthand.GodotSourceGenerator@1.1.1-beta.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Righthand.GodotSourceGenerator&version=1.1.1-beta.5&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Righthand.GodotSourceGenerator&version=1.1.1-beta.5&prerelease
                    
Install as a Cake Tool

godot-tscn-source-generator

Nuget (with prereleases)

Generates C# source code within Visual Studio 2022 based on Godot project.godot and .tscn files. Based on Righthand.GodotTscnParser which in turn uses ANTLR.

NOTE: Currently in alpha stage. If you have pull requests, problems or improvements ideas, feel free to create Issues. Also .tscn parser is probably not yet complete. If you find a case when generator doesn't create any code it could be that it failed parsing .tscn file (check build output). In such case I'd be interested in your .tscn file so I can update the parser.

Quick start

  1. Open a Godot solution in Visual Studio.
  2. Mark all .tscn files that will be used for code generation as "C# analyzer additional file" - select file in Solution Explorer and set its Build Action to C# analyzer additional file. Or alternatively add entry manually to .csproj as
<ItemGroup>
	<AdditionalFiles Include="FILENAME.cs" />
</ItemGroup>

where FILENAME should be replaced with relative path to file. Add AdditionalFiles node for each file.

  1. Install Righthand.GodotSourceGenerator from NuGet. Make sure you check "Include prerelease" as it is currently marked so.
  2. Build project.
  3. Use generated strong typed calls.

Sample generated code:

partial class Player
{
	public record struct AnimatedSprite2DNode
	{
		// ...
		public AnimatedSprite2D Instance => owner.GetNode<AnimatedSprite2D>("AnimatedSprite2D");
		// ...
		public static class SpriteFrames
		{
			public static StringName Up { get; } = "up";
			public static StringName Walk { get; } = "walk";
		}
	}
	public AnimatedSprite2DNode AnimatedSprite2D => new AnimatedSprite2DNode(this);
}

public static partial class InputActions
{
	public static StringName MoveLeft { get; } = "move_left";
	public static StringName MoveRight { get; } = "move_right";
	public static StringName MoveUp { get; } = "move_up";
	public static StringName MoveDown { get; } = "move_down";
	public static StringName StartGame { get; } = "start_game";
}

public static class Scenes
{
	public static readonly StringName Game = "res://Scenes/game.tscn";
	public static readonly StringName Hud = "res://Scenes/hud.tscn";
	public static readonly StringName Level = "res://Scenes/level.tscn";
	public static readonly StringName Start = "res://Scenes/start.tscn";
}

If you have a class named Player you can use

  1. AnimatedSprite2D.Instance method without explicitly using generic argument or node name.

  2. node.Animation = AnimatedSprite2DNode.SpriteFrames.Up instead of node.Animation = "up"

  3. if (Input.IsActionPressed(InputActions.MoveRight)) instead of if (Input.IsActionPressed("move_right)). Note that InputActions are global constants.

  4. Scenes.Level instead of "res://Scenes/level.tscn". If scenes are not within a Scenes directory, that root class will be PackedScenes and access will be like PackedScenes.SomeDirectory.SomeScene.

Besides providing Intellisense auto competition, it also helps when nodes are renamed in .tscn file. If this happens, code won't compile anymore, and it would require update.

When Scenes directory is not at the root of the project

If Scenes directory is not at the root of the project, you might set relative directory to avoid unnecessary nesting in Scenes class. This is done through a .csproj property like the sample below, when Scenes are located in src subdirectory:

<PropertyGroup>
    <TscnGeneratorGodotRoot>src/</TscnGeneratorGodotRoot>
</PropertyGroup>
<ItemGroup>
    <CompilerVisibleProperty Include="TscnGeneratorGodotRoot" />
</ItemGroup>

Make sure you include both TscnGeneratorGodotRoot and CompilerVisibleProperty, otherwise it won't work.

Generated code

  • Strong typed GetNode<T>(name) calls
  • Animation name constants
  • Input actions names
  • Node groups
  • Supports node nesting
  • Strong typed script resources

Sample

  • See refactored Dodge The Creeps Refactored

Roadmap

More code generation.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1-beta.5 87 3/21/2026
1.1.1-beta.4 75 1/18/2026
1.1.1-beta.3 85 12/31/2025
1.1.1-beta.2 89 12/29/2025
1.1.1-beta.1 78 12/29/2025
1.1.0-beta.2 94 12/28/2025
1.1.0-beta.1 138 12/21/2025
1.0.0-beta.2 156 6/3/2024
1.0.0-beta.1 292 10/16/2023
1.0.0-alpha9 237 3/26/2023
1.0.0-alpha8 236 3/25/2023
1.0.0-alpha7 226 3/19/2023
1.0.0-alpha6 217 3/17/2023
1.0.0-alpha5 220 3/16/2023
1.0.0-alpha4 226 3/12/2023
1.0.0-alpha3 218 3/7/2023
1.0.0-alpha2 227 3/5/2023
1.0.0-alpha11 221 3/26/2023
1.0.0-alpha10 209 3/26/2023
1.0.0-alpha.11 141 10/16/2023
Loading failed

- prefixes Timer instance with Godot. to avoid conflicts with System.Threading namespace