godot-csharp-patterns
Skill8 starsChanged 5 months agoMITView on GitHub
C# Mono patterns for Godot 4.x: Export attributes, signal handling, performance optimization, GDExtension interop, and best practices for first-class C# support. Use when writing C# code in Godot.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- MRCalderon3D/everything-game-dev-codetheir own version, first seen Oct 13, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- MRCalderon3D/everything-game-dev-code★ 105same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository23 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- godot-47-migrationSkill
- godot-animationSkill
- godot-architectureSkill
- godot-audioSkill
- godot-brainstormingSkill
- godot-code-reviewSkill
- godot-debuggingSkill
- godot-dialog-systemsSkill
- godot-gdscript-patternsSkill
- godot-headless-workflowSkill
- godot-i18nSkill
- godot-inputSkill
- godot-inventory-economySkill
- godot-networkingSkill
- godot-performanceSkill
- godot-physicsSkill
- godot-project-setupSkill
- godot-save-systemsSkill
- godot-shaders-vfxSkill
- godot-state-managementSkill
- godot-uiSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 219
Create a .gdextension file to expose C# classes to GDScript projects.
- Very specific: line 224
Use await with tweens for async animation sequences
- Distinctive: line 229
When the MCP bridge is running (Phase 2), these tools can inspect and modify your project live:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
C# Patterns for Godot 4.x
Best practices for Godot's first-class C# (Mono) support.
Export Attributes
Inspector Properties
using Godot;
public partial class Player : CharacterBody2D
{
// Basic export
[Export] public float Speed { get; set; } = 200f;
// With range
[Export(PropertyHint.Range, "0,100,0.5")]
public float JumpForce { get; set; } = 400f;
// File path
[Export(FileFilter = "*.png,*.svg")]
public string IconPath { get; set; } = "";
// Resource export
[Export] public PackedScene BulletScene { get; set; }
// Enum with hint
[Export] public MovementMode MoveMode { get; set; }
public enum MovementMode
{
Walk,
Run,
Sprint
}
}Export Categories
[ExportGroup("Combat")]
[Export] public int AttackDamage { get; set; } = 10;
[Export] public float AttackCooldown { get; set; } = 0.5f;
[ExportGroup("Movement")]
[Export] public float MoveSpeed { get; set; } = 200f;
[Export] public float JumpForce { get; set; } = 400f;Signal Handling
C# Event Syntax vs Godot Signals
// Godot signal declaration in GDScript (autoload)
// class_name EventBus extends Node
// signal player_died(Vector2 position)
// C# subscriber
public override void _Ready()
{
// Method reference (recommended — auto-disconnect on free)
EventBus.PlayerDied += OnPlayerDied;
// Lambda (requires manual disconnect)
EventBus.PlayerDied += (pos) => GD.Print($"Died at {pos}");
}
public override void _ExitTree()
{
// Clean up lambda subscriptions
EventBus.PlayerDied -= OnPlayerDied;
}
private void OnPlayerDied(Vector2 position)
{
GD.Print($"Player died at {position}");
}Using Godot.Signal for C#-Side Signals
public partial class Enemy : CharacterBody2D
{
[Signal] public delegate void HealthChangedEventHandler(int newHealth);
[Signal] public delegate void DefeatedEventHandler();
private int health = 100;
public void TakeDamage(int amount)
{
health -= amount;
EmitSignal(SignalName.HealthChanged, health);
if (health <= 0)
{
EmitSignal(SignalName.Defeated);
QueueFree();
}
}
}Performance Considerations
Avoiding GC Pressure
// Bad: Creates garbage every frame
public override void _Process(double delta)
{
var text = $"Score: {score}"; // String allocation
label.Text = text;
}
// Good: Reuse objects, avoid allocations
private readonly StringBuilder _sb = new();
public override void _Process(double delta)
{
_sb.Clear();
_sb.Append("Score: ");
_sb.Append(score);
label.Text = _sb.ToString();
}Structs vs Classes
// Use structs for small, short-lived data
public struct Vector2Int
{
public int X { get; }
public int Y { get; }
public Vector2Int(int x, int y) => (X, Y) = (x, y);
}
// Use classes for objects with identity/lifetime
public class PlayerData : Resource
{
public string Name { get; set; }
public int Level { get; set; }
}Instance Pooling
public partial class BulletPool : Node
{
private readonly Queue<Bullet> _pool = new();
private readonly PackedScene _bulletScene;
public BulletPool(PackedScene bulletScene) => _bulletScene = bulletScene;
public Bullet Get()
{
if (_pool.TryDequeue(out var bullet))
{
bullet.Visible = true;
return bullet;
}
return _bulletScene.Instantiate<Bullet>();
}
public void Return(Bullet bullet)
{
bullet.Visible = false;
bullet.QueueFree();
_pool.Enqueue(bullet);
}
}GDExtension Interop
Calling GDScript from C#
// GDScript (autoload "GameData")
// class_name GameData extends Node
// var high_score: int = 0
// C# access
var gameData = Engine.GetSingleton("GameData") as GodotObject;
var highScore = gameData.Get("high_score");Exposing C# to GDScript via GDExtension
Create a .gdextension file to expose C# classes to GDScript projects.
Godot 4.7 C# Notes
- C# fully supports new 4.7 features including VirtualJoystick and tween_await()
- Use
awaitwith tweens for async animation sequences - Export attributes work the same — no changes in 4.7
MCP Bridge Tools (Optional — Live Editor Integration)
When the MCP bridge is running (Phase 2), these tools can inspect and modify your project live:
script_read— Read C# script files for reviewscript_edit— Update C# scripts directlyscript_validate— Validate C# scripts for syntax errorsscene_tree— Inspect scene hierarchy to verify node compositionclass_db_info— Query Godot class info for C# interop patterns
Note: MCP tools require the Godot editor to be running with the MCP plugin enabled. Skills work independently without the bridge.
References
- C# API Reference
- Performance Guide
- GDExtension Guide
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

