godot-csharp
Use C#/.NET in Godot 4.7: partial classes extending nodes, the PascalCase lifecycle (_Ready/_Process/_PhysicsProcess), [Export] fields, [Signal] delegates as C# events, type-safe node lookup, and calling between C# and GDScript. Use when writing Godot game code in C# (.cs files, .csproj), needing the Godot .NET build, converting GDScript patterns to C#, or wiring Godot signals as C# events.
Overview
Godot C# / .NET (4.x)
Write Godot game code in C#: node subclasses, the engine lifecycle, exports, signals as events, and GDScript interop. Targets Godot 4.7 (.NET / C#) and .NET 8.
When to use
- Use when scripting a Godot game in C# (
.cs+.csproj), translating GDScript idioms to C#, exposing[Export]fields, or wiring[Signal]delegates and GetNode.
When not to use: GDScript-specific syntax → godot-gdscript; engine concepts that are language-neutral (scenes, physics, animation) → the relevant godot-* skill. You need the Godot .NET build + the .NET SDK installed; the standard build can't run C#.
Core workflow
- Use the Godot .NET editor build and install the matching .NET 8 SDK. Creating the first C# script generates a
.csproj/.sln. Build with the editor ordotnet build. - Every node script is a
partialclass extending a Godot type (the source generator relies onpartial). The file/class name should match the node script. - Override lifecycle methods in PascalCase with
doubledelta:_Ready(),_Process(double delta),_PhysicsProcess(double delta). - Expose tunables with
[Export]; they show in the Inspector like GDScript@export. - Declare signals as
[Signal]delegates namedXxxEventHandler; emit withEmitSignal(SignalName.Xxx, ...)and subscribe with the generated C#event. - Get nodes with
GetNode<T>("Path")(or%Unique), and call into GDScript withCall/Get/Setwhen needed.
Patterns
1. A node script: lifecycle, [Export], GetNode
using Godot;
public partial class Player : CharacterBody2D
{
[Export] public float Speed = 200.0f; // editable in the Inspector
[Export] public float JumpVelocity = -400.0f;
private const float Gravity = 1200.0f;
private AnimatedSprite2D _sprite;
public override void _Ready()
{
_sprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
}
public override void _PhysicsProcess(double delta)
{
Vector2 v = Velocity; // Velocity is a property here
if (!IsOnFloor())
v.Y += Gravity * (float)delta; // delta is double; cast for float math
if (Input.IsActionJustPressed("jump") && IsOnFloor())
v.Y = JumpVelocity;
float dir = Input.GetAxis("move_left", "move_right");
v.X = dir != 0 ? dir * Speed : Mathf.MoveToward(v.X, 0, Speed);
Velocity = v;
MoveAndSlide(); // no args, like GDScript 4.x
}
}2. Signals as C# events
using Godot;
public partial class Health : Node
{
// Delegate name MUST end with "EventHandler"; generator creates the event + SignalName.
[Signal] public delegate void HealthChangedEventHandler(int current, int max);
private int _hp = 100;
public void TakeDamage(int amount)
{
_hp = Mathf.Max(_hp - amount, 0);
EmitSignal(SignalName.HealthChanged, _hp, 100); // type-safe signal name
}
public override void _Ready()
{
HealthChanged += OnHealthChanged; // subscribe like a normal C# event
}
private void OnHealthChanged(int current, int max) => GD.Print($"HP {current}/{max}");
}3. Instancing a scene in C
public partial class Spawner : Node2D
{
// Load once; PackedScene is the C# equivalent of preload's result.
private readonly PackedScene _bullet = GD.Load<PackedScene>("res://bullet.tscn");
public void Shoot(Vector2 at)
{
var b = _bullet.Instantiate<Node2D>(); // typed instantiate
b.GlobalPosition = at;
AddChild(b);
}
}4. Interop with GDScript nodes
public override void _Ready()
{
Node gd = GetNode("GDScriptNode");
// Call a GDScript method and read/write its properties dynamically.
gd.Call("take_damage", 10);
int score = (int)gd.Get("score");
gd.Set("score", score + 5);
// Connect to a GDScript signal by name:
gd.Connect("died", Callable.From(OnDied));
}
private void OnDied() => GD.Print("entity died");Pitfalls
- Forgetting
partial. Withoutpartial, the Godot source generator can't extend the class and[Export]/[Signal]break with confusing build errors. - Wrong method case/signature. C# overrides are
_Ready,_Process(double),_PhysicsProcess(double)— PascalCase anddoubledelta (GDScript uses snake_case andfloat). A mismatched name just won't be called. [Signal]delegate naming. It must end withEventHandler; the engine exposes the signal as the name without that suffix and generatesSignalName.Xand a C#event.GD.PrintvsConsole.WriteLine. UseGD.Print/GD.PrintErrto reach the Godot output panel;Consoleoutput may not appear.- Value-type structs.
Vector2,Color,Transform2Dare structs — mutate a local copy (var v = Velocity; v.X = ...; Velocity = v;); editingVelocity.Xdirectly won't compile/persist. - Needs the .NET build + SDK. The non-.NET editor can't run C#; mismatched/missing .NET SDK causes build failures. Godot 4.7 targets .NET 8; check current platform export notes because Android and other AOT targets can require newer SDK tooling.
QueueFree()vsFree()— same rules as GDScript; preferQueueFree(). Disposed objects throwObjectDisposedExceptionif used after freeing.- Export to some platforms differs for .NET (e.g. extra steps for web/mobile); check the .NET export notes for your target.
References
- For export attribute variants (
[ExportGroup], ranges, typed arrays), async withawait ToSignal(...),Godot.Collectionsvs System collections, custom Resources in C#, and project/build setup, readreferences/csharp-setup-and-interop.md.
Related skills
godot-gdscript— the GDScript equivalents of these patterns.godot-signals-groups— signal/event architecture (language-neutral).godot-resources— data resources; the C#[Export]+Resourcepattern.unity-csharp-scripting— C# in Unity, for developers coming from there.
Files 2 files
Install it by hand
Deska runs this for you, for every agent you pick. To run it yourself in a terminal:
npx skills add gamedev-skills/awesome-gamedev-agent-skills --skill godot-csharpMore from gamedev-skills
- game-feelgamedev-skillsAdd "juice" and game feel that makes actions satisfying — screen shake, hit-stop/freeze frames, tweened/eased motion, squash & stretch, knockback, and layered audio-visual feedback — as engine-neutral techniques that pair with the detected engine's tween, particle, and camera APIs. Use when the user mentions game feel, juice, "make it feel good/punchy", screen shake, hit stop, screen freeze, easing, squash and stretch, impact frames, or feedback/polish on hits, jumps, pickups, and deaths.5,900 installs on skills.sh0
- game-ui-uxgamedev-skillsDesign and build game UI/UX — HUDs, menus, and overlays — that survive every screen: anchor- based responsive layout, resolution/aspect scaling and safe areas, keyboard/gamepad focus navigation, a screen/menu state stack, and event-driven (not polled) HUD updates. Engine- neutral patterns that pair with the detected engine's UI skill. Use when the user mentions HUD, health bar, main menu, pause menu, settings screen, UI layout, anchors, UI scaling, aspect ratio, safe area, controller/keyboard menu navigation, or wiring UI to game state.5,900 installs on skills.sh0
- level-designgamedev-skillsDesign and build playable levels — the blockout/whitebox-to-playable workflow, player metrics and grid layout, pacing and flow (tension/rest curve), gating and the critical path, and encounter design. Engine-neutral practice. Use when the user mentions level design, blockout/whitebox/greybox, level layout, level pacing, encounter design, or the critical path through a level.4,700 installs on skills.sh0
- game-aigamedev-skillsDesign NPC and enemy decision-making with finite state machines, behavior trees, steering behaviors, and A* pathfinding — engine-neutral algorithms that pair with the detected engine's navigation API. Use when building enemy AI, an FSM or behavior tree, steering/flocking, or pathfinding, or when the user mentions state machine, behavior tree, blackboard, A*, navmesh, seek, or patrol/chase.4,500 installs on skills.sh0
- audio-designgamedev-skillsImplement game audio practice — bus/mixer architecture and gain in decibels, ducking (sidechain), adaptive/dynamic music via layering and re-sequencing, SFX variation, and beat synchronization. Engine-neutral. Use when the user mentions audio mixing, audio buses, adaptive/dynamic music, ducking, SFX variation, music layers, or syncing gameplay to the beat.4,400 installs on skills.sh0