Home › Unity (C#) › Unity 6 C# Windsurf rules

Unity 6 C# Windsurf rules

Windsurf rules for Unity 6 projects in C#: MonoBehaviour lifecycle, ScriptableObjects, Input System, and performance.

WindsurfUnity (C#)

How to use

Save this as .windsurf/rules/unity.md 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.

.windsurf/rules/unity.mdDownload  
---
trigger: glob
globs: Assets/**/*.cs
---

# Unity 6 (C#)

- Serialize private fields with `[SerializeField] private float speed = 5f;` instead of public fields. Validate in `OnValidate`.
- Cache components in `Awake` (`TryGetComponent`), subscribe to events in `OnEnable`, unsubscribe in `OnDisable`. No `GetComponent`, `Find`, or `Camera.main` lookups in `Update`.
- Physics in `FixedUpdate` with `Rigidbody` (`linearVelocity` in Unity 6); frame logic in `Update` scaled by `Time.deltaTime`.
- Data and config in `ScriptableObject` assets; avoid singletons holding game state where an SO or a scene service works.
- Input with the Input System package (generated C# class or `PlayerInput` actions), not the legacy `Input.GetKey`.
- Async: `Awaitable` / `async` methods (Unity 6) or coroutines; cancel with `destroyCancellationToken`.
- Avoid per-frame allocations (LINQ, string concat, `new` lists); use object pooling (`UnityEngine.Pool.ObjectPool<T>`).
- Assets loaded via Addressables if the project uses them; never `Resources.Load` in new code without reason.
- Namespaces per feature; one MonoBehaviour per file with a matching name.
- Wrap editor-only code in `#if UNITY_EDITOR`.

## Don't
- Don't edit `.meta`, `.unity`, or `.prefab` YAML by hand.

## Done when
No compiler warnings in the Console, and EditMode/PlayMode tests (Test Runner) pass.

More: all Unity (C#) rules · all Windsurf rules

Related rules

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#)

Phaser 3 browser game rules

Windsurf rules for 2D browser games with Phaser 3, TypeScript and Vite.

WindsurfPhaser (web games)

Bevy game engine AGENTS.md

AGENTS.md for Bevy (0.16+) games in Rust: ECS systems, plugins, required components, and fast dev builds.

AGENTS.mdBevy (Rust)

Defold game engine AGENTS.md

AGENTS.md for Defold games in Lua: game objects and components, message passing, script lifecycle, and native extensions.

AGENTS.mdDefold

GameMaker GML AGENTS.md

AGENTS.md for GameMaker (2024+ runtime) projects in GML: objects and events, structs and methods, and clean state.

AGENTS.mdGameMaker

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.