Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use when working with C# in Godot — conventions, GodotSharp API differences from GDScript, project setup, and interop
.claude/skills/jame581-csharp-godot/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-11 | ✗→✓ | ▲ Improved | 339% | 0% |
| case-05 | ✓→✓ | = Same ✓ | 205% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 333% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 618% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 178% | 0% |
This skill covers C#-specific conventions, API differences from GDScript, project setup, and interop patterns. All examples are C# only. Target Godot 4.3+ with the GodotSharp NuGet package.
> Related skills: csharp-signals for C# signal patterns, godot-project-setup for C# project scaffolding, godot-testing for C# testing with gdUnit4, gdextension for native C++ when C# is not enough, multithreading for C# concurrency.
| GDScript | C# Equivalent | Notes | |---|---|---| | var x = 5 | var x = 5; or typed int x = 5; | C# var infers type at compile time | | func MyMethod() -> void: | public void MyMethod() { } | Methods are PascalCase in C# | | signal health_changed(amount: int) | [Signal] delegate void HealthChangedEventHandler(int amount); | Must use EventHandler suffix | | @export var speed: float = 100.0 | [Export] public float Speed { get; set; } = 100f; | PascalCase, property syntax | | @onready var label = $Label | private Label _label; + _label = GetNode<Label>("Label"); in _Ready() | No @onready equivalent; use _Ready() | | match value: | switch (value) { case X: break; } | C# switch also supports pattern matching | | class_name MyClass | [GlobalClass] public partial class MyClass : GodotObject { } | Requires [GlobalClass] attribute | | extends Node | public partial class MyScript : Node { } | Inheritance via : | | preload("res://scene.tscn") | GD.Load<PackedScene>("res://scene.tscn") | Loaded at runtime, not compile time | | push_error("msg") | GD.PushError("msg"); | Prints to Godot error log | | print("msg") | GD.Print("msg"); | Also: GD.PrintS(), GD.PrintT() | | node is CharacterBody2D | node is CharacterBody2D | Same keyword, same semantics | | node as CharacterBody2D | node as CharacterBody2D | Returns null on failure in both | | await signal_name | await ToSignal(source, SignalName.X); | Must use ToSignal() wrapper | | Array | Godot.Collections.Array | Not System.Collections.Generic.List<T> | | Dictionary | Godot.Collections.Dictionary | Not System.Collections.Generic.Dictionary<K,V> |
Godot auto-generates the .csproj when you create the first C# script via Script > New Script > C#. Do not edit the generated file structure manually — let the editor manage it.
MyProject/
├── MyProject.csproj # Auto-generated, edit only for NuGet packages
├── MyProject.sln # Auto-generated solution file
├── project.godot
└── scripts/
└── Player.csAdd packages in MyProject.csproj inside <ItemGroup>:
xml<Project Sdk="Godot.NET.Sdk/4.3.0"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <Nullable>enable</Nullable> <AllowUnsafeBlocks>true</AllowUnsafeBlocks> </PropertyGroup> <ItemGroup> <!-- Example: add a third-party NuGet package --> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> </ItemGroup> </Project>
Run dotnet restore or let the IDE restore automatically after editing.
Godot 4.7's Godot.NET.Sdk accepts an opt-in MSBuild property that switches the project from the classic GodotSharp bindings to the preview Godot.NET bindings (the Godot.Bindings assembly instead of GodotSharp):
xml<PropertyGroup> <EnableGodotDotNetPreview>true</EnableGodotDotNetPreview> </PropertyGroup>
The preview bindings are experimental — leave the property unset for production projects. See GH-118001.
| IDE | Setup Required | Notes | |---|---|---| | JetBrains Rider | Install Godot plugin (bundled in Rider 2023.3+) | Best Godot C# support; debugger works out of the box | | VS Code | Install C# Dev Kit + Godot Tools extensions | Requires launch.json for debugger attachment | | Visual Studio | Install Godot Visual Studio extension | Windows only; debugger via Tools > Attach to Process |
For all IDEs, open the .sln file (not just a folder) to get full solution resolution.
partial class RequirementEvery class that extends a Godot type must be declared partial. This is not optional.
Godot uses C# source generators to emit the signal registration, property binding, and RPC code alongside your class. Source generators require partial to inject into the same class declaration.
Error CS0260: Missing partial modifier on declaration of type 'Player';
another partial declaration of this type exists.Or the class compiles but signals and [Export] properties silently fail to register.
csharp// CORRECT public partial class Player : CharacterBody2D { } // WRONG — will cause source generator errors public class Player : CharacterBody2D { }
This applies to every class in the inheritance chain that extends a Godot type, including intermediate base classes.
| Element | Convention | Example | |---|---|---| | Methods | PascalCase | public void TakeDamage(int amount) | | Properties | PascalCase | public float MaxHealth { get; set; } | | Signals (delegate) | PascalCase + EventHandler suffix | HealthChangedEventHandler | | [Export] properties | PascalCase | [Export] public float Speed { get; set; } | | Private fields | _camelCase with underscore prefix | private float _currentSpeed; | | Local variables | camelCase | var newPosition = ... | | Parameters | camelCase | void SetHealth(int newHealth) | | Godot API names | Match Godot's PascalCase exactly | GlobalPosition not global_position | | Enums | PascalCase type, PascalCase members | enum State { Idle, Running, Dead } | | Constants | PascalCase or SCREAMING_SNAKE per team style | const float MaxSpeed = 200f; |
Always match GodotSharp property and method names exactly — they are PascalCase translations of the GDScript snake_case names (e.g. is_on_floor() → IsOnFloor()).
Signals require a delegate declaration with the [Signal] attribute. The delegate name must end with EventHandler.
csharpusing Godot; public partial class Player : CharacterBody2D { // Declaration [Signal] public delegate void HealthChangedEventHandler(int newHealth); [Signal] public delegate void DiedEventHandler(); private int _health = 100; public void TakeDamage(int amount) { _health -= amount; EmitSignal(SignalName.HealthChanged, _health); // Use SignalName.X, not a string if (_health <= 0) EmitSignal(SignalName.Died); } }
csharp// Connect with += player.HealthChanged += OnHealthChanged; player.Died += OnPlayerDied; // Disconnect with -= player.HealthChanged -= OnHealthChanged; player.Died -= OnPlayerDied; // Handler signatures must match the delegate private void OnHealthChanged(int newHealth) { ... } private void OnPlayerDied() { ... }
> For full signal patterns including one-shot connections, static typed signals, and cross-language signal wiring, see the csharp-signals skill.
GDScript's await maps to C#'s await ToSignal(...). Godot signals return a SignalAwaiter that is compatible with C# await.
csharppublic async void StartCutscene() { // Wait for a timer to finish await ToSignal(GetTree().CreateTimer(2.0), Timer.SignalName.Timeout); // Wait for an animation to finish var anim = GetNode<AnimationPlayer>("AnimationPlayer"); anim.Play("intro"); await ToSignal(anim, AnimationPlayer.SignalName.AnimationFinished); GD.Print("Cutscene complete"); }
For CPU-bound work, use Task.Run — but never touch Godot objects from a non-main thread:
csharppublic async void LoadHeavyData() { // Off main thread: pure C# computation only var result = await Task.Run(() => ComputeSomethingExpensive()); // Back on main thread: safe to use Godot API ApplyResult(result); } private int ComputeSomethingExpensive() { // No Godot API calls here return Enumerable.Range(0, 1_000_000).Sum(); }
await Equivalents| GDScript | C# | |---|---| | await get_tree().create_timer(1.0).timeout | await ToSignal(GetTree().CreateTimer(1.0), Timer.SignalName.Timeout) | | await animation_player.animation_finished | await ToSignal(animPlayer, AnimationPlayer.SignalName.AnimationFinished) | | await signal_name | await ToSignal(this, SignalName.YourSignal) |
Use Call, Get, and Set on any GodotObject. Values are marshalled through Variant.
csharp// Assume "enemy" is a GodotObject backed by a GDScript with func take_damage(amount) GodotObject enemy = GetNode("Enemy"); // Call a GDScript method enemy.Call("take_damage", 25); // Get a GDScript property float health = enemy.Get("health").AsSingle(); // Set a GDScript property enemy.Set("is_stunned", true);
If a C# class is registered as a [GlobalClass], GDScript can instantiate and use it directly without any extra wiring:
csharp[GlobalClass] public partial class WeaponData : Resource { [Export] public float Damage { get; set; } = 10f; [Export] public float Cooldown { get; set; } = 0.5f; }
gdscript# GDScript — works because WeaponData is a [GlobalClass] var data := WeaponData.new() data.damage = 50.0
Non-[GlobalClass] C# types are not visible to GDScript by name but can still be passed as Variant/Object references.
| Scenario | Issue | Fix | |---|---|---| | Passing null across boundary | GDScript null becomes default(Variant), not C# null | Check variant.VariantType == Variant.Type.Nil | | Returning int[] from C# | GDScript receives a PackedInt32Array, not an Array | Return Godot.Collections.Array<int> for consistent typing | | Passing System.Collections.Generic.List<T> | Not marshallable — Godot doesn't know this type | Convert to Godot.Collections.Array<T> first | | Godot Color struct | Passed by value through Variant correctly | No issue |
| Workload | Winner | Reason | |---|---|---| | Math-heavy loops (pathfinding, simulation) | C# (significantly faster) | Compiled JIT vs interpreted GDScript | | Large array/collection processing | C# | Value type arrays avoid boxing | | Godot API calls (move_and_slide, etc.) | Roughly equal | Both route through the same C++ engine | | Scene tree operations | Roughly equal | Bottleneck is C++ overhead, not language | | Rapid prototyping | GDScript | Less boilerplate, hot-reload without recompile | | Editor tooling (plugins, @tool) | GDScript | C# tool scripts require a full build cycle |
@tool scripts, and rapid iteration on gameplay logic.Godot.Collections.Array for hot paths; prefer typed arrays (Array<T>) or native C# arrays (T[]) converted at boundaries.StringName lookups are O(1) but StringName construction is not — cache them if created frequently.| Gotcha | Problem | Fix | |---|---|---| | Variant to C# type conversion | (float)someVariant throws if the underlying type is int | Use .AsSingle(), .AsInt32(), etc. instead of casts | | null vs default(Variant) | Godot signals passing no value give default(Variant), not C# null | Check .VariantType == Variant.Type.Nil | | Godot.Collections vs System.Collections | Godot API methods return Godot.Collections.Array; passing List<T> causes runtime error | Always use Godot.Collections.Array/Dictionary at Godot API boundaries | | Disposing native objects | Calling methods on a freed Godot object throws ObjectDisposedException | Check IsInstanceValid(obj) before use | | StringName construction in hot loops | new StringName("my_signal") allocates each call | Cache as private static readonly StringName _signalName = "my_signal"; | | Export array types | [Export] public Array Items; exports untyped array | Use [Export] public Godot.Collections.Array<MyResource> Items { get; set; } | | Node path strings | GetNode("../UI/Label") fails silently if the path changes | Use GetNode<Label>("%Label") with unique names or typed [Export] node references | | partial class forgotten | Source generators silently fail; [Export] and [Signal] don't register | Every class extending a Godot type must be partial | | async void vs async Task | async void swallows exceptions | Use async Task except for top-level event handlers that Godot calls |
> ⚠️ Changed in Godot 4.7: The 4.7 C# assemblies ship several compatibility breaks. Binary-incompatible only (source still compiles — a rebuild suffices): OptimizedTranslation.Generate() now returns bool instead of void (GH-119563). Binary- and source-incompatible (code changes required): Animation.Length changed type metadata from float to double (GH-116394) — the C# property is now double, so float len = anim.Length; no longer compiles — and Control.AccessibilityLive changed enum type from DisplayServer.AccessibilityLiveMode to AccessibilityServer.AccessibilityLiveMode (GH-116839) — update declarations to the AccessibilityServer enum. Source-incompatible (existing binaries still load): RichTextLabel.ImageUpdateMask.UpdateWidthInPercent was renamed to UpdateWidthUnit (GH-112617), and the EditorSceneFormatImporter IMPORT_* constants moved into the ImportFlags enum (GH-115788). Removed: AudioEffectSpectrumAnalyzer.TapBackPos (GH-114355). Rebuild against 4.7 and fix the affected symbols. See the 4.7 migration guide.
partial_Ready, _PhysicsProcess, IsOnFloor())[Export] properties are PascalCase and use property syntax ({ get; set; })EventHandler and use EmitSignal(SignalName.X)+= and disconnected with -= when no longer neededawait ToSignal(...) used for Godot signals — not raw Task.Delay for game timingGodot.Collections.Array/Dictionary used at Godot API boundaries, not System.Collections typesIsInstanceValid(obj) checked before using any potentially freed Godot objectStringName instances cached if constructed in loops or frequently called methodsTask.Run(...) callbacks — all engine calls happen on the main thread.csproj opened via the .sln file in the IDE for full solution resolution@tool scripts| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-05 | pass→pass | 9,420 | 4,683 | -50% | 1 | 1 | 0% | 1,661 | 5,064 | +205% | 0 | 0 | — |
case-01 | pass→pass | 7,096 | 6,401 | -10% | 1 | 1 | 0% | 1,232 | 5,332 | +333% | 0 | 0 | — |
case-02 | pass→pass | 4,137 | 2,971 | -28% | 1 | 1 | 0% | 653 | 4,686 | +618% | 0 | 0 | — |
case-03 | pass→pass | 10,891 | 3,478 | -68% | 1 | 1 | 0% | 1,734 | 4,823 | +178% | 0 | 0 | — |
case-04 | pass→pass | 5,589 | 5,170 | -7% | 1 | 1 | 0% | 944 | 5,194 | +450% | 0 | 0 | — |
case-06 | pass→pass | 8,912 | 6,816 | -24% | 1 | 1 | 0% | 1,468 | 5,365 | +265% | 0 | 0 | — |
case-07 | pass→pass | 13,039 | 5,674 | -56% | 1 | 1 | 0% | 2,194 | 5,196 | +137% | 0 | 0 | — |
case-08 | pass→pass | 4,617 | 3,579 | -22% | 1 | 1 | 0% | 786 | 4,868 | +519% | 0 | 0 | — |
case-09 | pass→pass | 7,817 | 5,722 | -27% | 1 | 1 | 0% | 1,402 | 5,218 | +272% | 0 | 0 | — |
case-10 | pass→pass | 13,899 | 8,556 | -38% | 1 | 1 | 0% | 2,336 | 5,781 | +147% | 0 | 0 | — |
case-11 | fail→pass | 6,430 | 1,786 | -72% | 1 | 1 | 0% | 1,034 | 4,542 | +339% | 0 | 0 | — |
case-12 | pass→pass | 15,146 | 2,228 | -85% | 1 | 1 | 0% | 2,383 | 4,645 | +95% | 0 | 0 | — |
case-13 | pass→pass | 9,587 | 4,368 | -54% | 1 | 1 | 0% | 1,613 | 4,978 | +209% | 0 | 0 | — |
case-14 | pass→pass | 12,410 | 4,826 | -61% | 1 | 1 | 0% | 1,982 | 5,080 | +156% | 0 | 0 | — |
case-15 | pass→pass | 4,108 | 3,170 | -23% | 1 | 1 | 0% | 674 | 4,766 | +607% | 0 | 0 | — |
case-16 | pass→pass | 10,301 | 6,154 | -40% | 1 | 1 | 0% | 1,614 | 5,285 | +227% | 0 | 0 | — |
case-17 | pass→pass | 8,139 | 5,157 | -37% | 1 | 1 | 0% | 1,469 | 5,191 | +253% | 0 | 0 | — |
case-18 | pass→pass | 4,439 | 3,102 | -30% | 1 | 1 | 0% | 819 | 4,823 | +489% | 0 | 0 | — |
case-19 | pass→pass | 9,135 | 7,684 | -16% | 1 | 1 | 0% | 1,617 | 5,658 | +250% | 0 | 0 | — |
case-20 | pass→pass | 12,027 | 5,170 | -57% | 1 | 1 | 0% | 1,961 | 5,129 | +162% | 0 | 0 | — |
case-21 | pass→pass | 9,149 | 7,951 | -13% | 1 | 1 | 0% | 1,604 | 5,776 | +260% | 0 | 0 | — |
case-22 | pass→pass | 3,686 | 2,951 | -20% | 1 | 1 | 0% | 519 | 4,691 | +804% | 0 | 0 | — |
case-23 | pass→pass | 3,417 | 2,291 | -33% | 1 | 1 | 0% | 508 | 4,574 | +800% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +4 percentage points is the difference between those two pass rates over the 23 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.