Skip to content
vibespell

.cursor/rules/project.mdc

Cursor rules for Unity

Cursor rules are a markdown file with a short frontmatter header. Cursor attaches them to the agent so it stops guessing how this repo builds, tests, and styles code. This copy is written for a Unity project. This repository is a Unity project in C#. Compose behavior with components, expose inspector values with SerializeField, and keep the Unity API on the main thread.

The example uses a balanced, readable style, pragmatic tests, and comments only where the intent is not obvious. Open the generator to make the agent stricter, switch to test-first, quiet the comments, or pick a different file.

The example assumes Unity LTS and C# MonoBehaviours. It does not assume Netcode, Addressables, or a particular input system. If the project uses the new Input System or a custom framework, follow that.

Example file

Balanced strictness, readable style, pragmatic tests. Download name: project.mdc. Legacy path: .cursorrules

---
description: "Working rules for a Unity repository"
globs: "**/*"
alwaysApply: true
---

# Project rules

Follow these rules on every task in this Unity repository.
If the project still uses a root `.cursorrules` file, keep the same rules there.

## Stack

This repository is a Unity project in C#. Compose behavior with components, expose inspector values with SerializeField, and keep the Unity API on the main thread.

## Layout

- Runtime scripts live under `Assets/` in the folder the feature already uses.
- Editor-only code lives in an `Editor` folder or an editor assembly definition.
- Prefabs and ScriptableObjects are the data. Do not hard-code tuning numbers that designers already edit in the inspector.

## Commands

- Open: `Open the project in the Unity Editor for this version`
- Tests: `Window > General > Test Runner`
- Play: `Enter Play Mode from the scene you changed`

Use the script the repo already defines when it differs from the command above.

## Conventions

- Expose inspector fields with `[SerializeField]` and a private field. Do not make fields public just to show them.
- Cache component references in `Awake` or via `[SerializeField]`. Do not call `GetComponent` or `Find` methods inside `Update`.
- Use events, UnityEvents, or a message the project already has. Do not poll a flag every frame when a callback exists.
- Scene and prefab changes are part of the change. Do not leave a missing script behind.
- Keep gameplay code out of `Editor` assemblies, and editor windows out of runtime assemblies.
- Match the naming already in the assembly: PascalCase for types and methods, the project's field prefix if it has one.

## Testing

Add or update tests when behavior changes.

Use the Unity Test Framework. Prefer an Edit Mode test for pure C# and a Play Mode test only when you need the engine.

## Style

- Optimize for the next reader over the shortest diff.
- Comment only when the why is non-obvious.
- Name things the way neighboring files already do.
- Do not reformat code you did not change.

## Errors

- Fail at the boundary. Do not swallow errors.
- Log with context (`Debug.LogError(message, this)`) for unexpected states. Disable the component or skip the frame for a missing optional reference, and say which reference.

## Scope

- Do the requested task. Do not refactor unrelated code.
- Match the rigor already in the repo. Fix what you touch.
- Ask one clarifying question only when the task cannot be finished without it. Otherwise state the assumption and continue.

## Avoid

- Do not touch `UnityEngine` objects from a worker thread.
- Do not use `GameObject.Find` or `FindObjectOfType` in `Update`.
- Do not compare tags with `==` on a typo-prone string when `CompareTag` will do.
- Do not commit `Library/` or other generated folders. Respect the project's `.gitignore`.

## Done when

- The requested behavior works.
- The script compiles in the Editor, and you ran the Test Runner or Play Mode for the scene you touched.
- The diff stays inside the task.
- You list anything you could not run.

Add it to the project

  1. 01

    Copy a starting file

    Copy the example Cursor rules on this page, or open the generator if you want different testing, strictness, or comment rules.

  2. 02

    Save it at .cursor/rules/project.mdc

    Save it at `.cursor/rules/project.mdc` in the Unity repo and create the folders if they are missing. If the project still uses one root rules file, save the body as `.cursorrules`.

  3. 03

    Start a fresh agent session

    Rules files are read when a session starts. A chat that is already open may still be using the old instructions.

  4. 04

    Give it one small task

    Ask for one change a Unity agent often gets wrong, such as a component that moves work out of Update when it only needs to react to an event. If it ignores the file, confirm the path and start a new session.

Questions about this file

Where do I put Cursor rules in a Unity repo?

Save it at `.cursor/rules/project.mdc` in the Unity repo and create the folders if they are missing. If the project still uses one root rules file, save the body as `.cursorrules`.

Which tools read this Cursor rules?

Cursor reads `.cursor/rules/*.mdc` and, on older setups, a root `.cursorrules` file. Other tools ignore the frontmatter, so use AGENTS.md when more than one agent edits the repo.

What does the Unity example assume?

The example assumes Unity LTS and C# MonoBehaviours. It does not assume Netcode, Addressables, or a particular input system. If the project uses the new Input System or a custom framework, follow that.

Does VibeSpell upload my repository?

No. Recipe pages are static, and the generator builds the file in your browser from the options you pick. Your source code never leaves the machine.

Other files for Unity

Cursor rules for other stacks