Home › Godot › Godot 4 C# rules

Godot 4 C# rules

Cursor rules for Godot 4.x games written in C# (.NET 8): node scripts, signals, exports, and performance.

CursorGodot

How to use

Save this as .cursor/rules/godot-csharp.mdc in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.cursor/rules/godot-csharp.mdcDownload  
---
description: Godot 4 C# conventions
globs: ["**/*.cs"]
alwaysApply: false
---

# Godot 4 (C#)

- Scripts are `public partial class Player : CharacterBody2D`. The class name must match the file name, and the class must be `partial`.
- Use Godot's lifecycle: `_Ready` for setup, `_Process(double delta)` for frame logic, `_PhysicsProcess` for movement and physics. Multiply by `delta`.
- Node references: `[Export]` fields assigned in the editor, or `GetNode<T>("%UniqueName")` cached in `_Ready`. Don't call `GetNode` every frame.
- Signals: declare with `[Signal] public delegate void HealthChangedEventHandler(int value);`, emit with `EmitSignal(SignalName.HealthChanged, hp)`. Prefer the generated `SignalName`/`MethodName` constants over strings.
- Unsubscribe C# `+=` event handlers in `_ExitTree` to avoid leaks and calls on freed objects.
- Use `Godot.Collections` only when crossing into the engine; use `System.Collections.Generic` inside C# logic.
- Avoid allocations in `_Process` (no LINQ, no `new` per frame). Check `IsInstanceValid` before touching nodes that may be freed.
- Free nodes with `QueueFree()`. Load resources with `GD.Load<T>` once, or preload in exports.
- Input via actions defined in Project Settings (`Input.IsActionPressed("jump")`), not raw keys.
- After adding exported properties or signals, rebuild (`dotnet build`) so the editor sees them.

## Don't
- Don't edit `.tscn`/`.tres` files by hand beyond simple property changes.

## Done when
`dotnet build` succeeds with no warnings, and the scene runs.

More: all Godot rules · all Cursor rules

Related rules

Godot 4 GDScript AGENTS.md

AGENTS.md for Godot 4 projects using typed GDScript, signals and scene composition.

AGENTS.mdGodot

LÖVE (Love2D) Lua game rules

Cursor rules for 2D games with LÖVE 11.5 in Lua: callbacks, modules, delta time, asset loading, and performance.

CursorLÖVE (Love2D)

Roblox Luau rules

Cursor rules for Roblox experiences in Luau: strict typing, client/server boundaries, remotes, and data saving.

CursorRoblox (Luau)

Three.js rules

Cursor rules for Three.js (r17x, ES modules) web 3D and games: render loop, disposal, assets, and performance.

CursorThree.js

Unity C# game dev rules

Cursor rules for Unity 6 projects in C#: performance, MonoBehaviour lifecycle, ScriptableObjects.

CursorUnity (C#)

Unity DOTS / ECS rules

Cursor rules for Unity Entities 1.x (DOTS): baking, ISystem with Burst, jobs, IJobEntity, and structural changes.

CursorUnity (C#)

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.