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.

.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.

Related rules

Web accessibility (WCAG 2.2) rules

Windsurf rules for building accessible web UIs to WCAG 2.2 AA: semantics, keyboard, focus, contrast, and testing.

WindsurfAccessibility

Django Windsurf rules

Windsurf rules for Django 5.2 LTS projects: apps, models and migrations, ORM performance, forms, and tests.

WindsurfDjango

Documentation writing rules

Windsurf rules for writing and updating READMEs, docstrings, ADRs, and changelogs alongside code changes.

WindsurfAgent workflows

Electron app Windsurf rules

Windsurf rules for secure Electron 44 apps: context isolation, preload bridges, typed IPC, and packaging.

WindsurfElectron

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.