From ff3a52d5b38b6aaf959b9a7589dc93fc6ad6f92d Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 21 Oct 2026 13:32:23 +0000 Subject: [PATCH] Add Unity 6 C# instructions Add instructions/unity-6-csharp.instructions.md for Unity 6.3 LTS and regenerate docs/README.instructions.md. Co-authored-by: Anthony Pan --- docs/README.instructions.md | 1 + instructions/unity-6-csharp.instructions.md | 79 +++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 instructions/unity-6-csharp.instructions.md diff --git a/docs/README.instructions.md b/docs/README.instructions.md index 710960f3d6..1b20721cfb 100644 --- a/docs/README.instructions.md +++ b/docs/README.instructions.md @@ -204,6 +204,7 @@ See [CONTRIBUTING.md](../CONTRIBUTING.md#adding-instructions) for guidelines on | [Terraform on SAP BTP – Best Practices & Conventions](../instructions/terraform-sap-btp.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fterraform-sap-btp.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fterraform-sap-btp.instructions.md) | Terraform conventions and guidelines for SAP Business Technology Platform (SAP BTP). | | [TypeScript MCP Server Development](../instructions/typescript-mcp-server.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftypescript-mcp-server.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftypescript-mcp-server.instructions.md) | Instructions for building Model Context Protocol (MCP) servers using the TypeScript SDK | | [TypeSpec for Microsoft 365 Copilot Development Guidelines](../instructions/typespec-m365-copilot.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftypespec-m365-copilot.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftypespec-m365-copilot.instructions.md) | Guidelines and best practices for building TypeSpec-based declarative agents and API plugins for Microsoft 365 Copilot | +| [Unity 6 C# rules](../instructions/unity-6-csharp.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Funity-6-csharp.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Funity-6-csharp.instructions.md) | Unity 6.3 LTS C# rules: read input through the Input System package instead of Input.GetAxis, use Rigidbody.linearVelocity, replace obsolete FindObjectOfType with FindAnyObjectByType or serialized references, and never edit .meta files. | | [Update Code from Shorthand](../instructions/update-code-from-shorthand.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fupdate-code-from-shorthand.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fupdate-code-from-shorthand.instructions.md) | Shorthand code will be in the file provided from the prompt or raw data in the prompt, and will be used to update the code file when the prompt has the text `UPDATE CODE FROM SHORTHAND`. | | [Update Documentation on Code Change](../instructions/update-docs-on-code-change.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fupdate-docs-on-code-change.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fupdate-docs-on-code-change.instructions.md) | Automatically update README.md and documentation files when application code changes require documentation updates | | [Upgrading from .NET MAUI 9 to .NET MAUI 10](../instructions/dotnet-maui-9-to-dotnet-maui-10-upgrade.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fdotnet-maui-9-to-dotnet-maui-10-upgrade.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fdotnet-maui-9-to-dotnet-maui-10-upgrade.instructions.md) | Instructions for upgrading .NET MAUI applications from version 9 to version 10, including breaking changes, deprecated APIs, and migration strategies for ListView to CollectionView. | diff --git a/instructions/unity-6-csharp.instructions.md b/instructions/unity-6-csharp.instructions.md new file mode 100644 index 0000000000..2c106c0441 --- /dev/null +++ b/instructions/unity-6-csharp.instructions.md @@ -0,0 +1,79 @@ +--- +description: "Unity 6.3 LTS C# rules: read input through the Input System package instead of Input.GetAxis, use Rigidbody.linearVelocity, replace obsolete FindObjectOfType with FindAnyObjectByType or serialized references, and never edit .meta files." +applyTo: "**/*.cs" +--- + +# Unity 6 C# rules + +Pinned to Unity 6.3 LTS (6000.3.x, supported through December 2027). The same calls are valid on the 6000.6 update line checked 2026-10-15, with one exception called out below. Do not emit Unity 2022 or earlier APIs. + +## Project files +- Never delete, rename, or hand-edit a `.meta` file. Unity stores the asset GUID there. Deleting one reimports the asset and breaks every reference to it. +- Do not run `dotnet build` to "check" a Unity project. The editor compiles assemblies itself. A bare `dotnet build` fails or compiles the wrong set of asmdefs. +- Edit scripts under `Assets/`. Do not write into `Library/`, `Temp/`, `Obj/`, or `Logs/`. + +## Finding objects +- `Object.FindObjectOfType` and `FindObjectsOfType` are obsolete. Do not use them. +- When any match is fine, use `Object.FindAnyObjectByType()`. Do not call it from `Update` or `FixedUpdate`. Cache the result in `Awake` or `Start`. +- On Unity 6.6 and newer, `FindFirstObjectByType` is also obsolete, because it depended on InstanceID ordering. Do not use it. If you need a specific object, query with `FindObjectsByType()` and sort by something real, such as sibling index. +- Prefer a serialized reference (`[SerializeField] private Player player;`) over any Find call. + +## Input and physics +- Read input through the Input System package (`UnityEngine.InputSystem`). Do not call `Input.GetAxis`, `Input.GetKey`, or `Input.GetButton`. Those throw when the project is set to the new Input System only, which is the Unity 6 default for new projects. +- Read buttons in `Update`. Write to a Rigidbody in `FixedUpdate`. +- The velocity property is `Rigidbody.linearVelocity` (world space, units per second). `Rigidbody.velocity` does not exist in Unity 6. Do not assign `linearVelocity` every physics step. Use `AddForce` for ongoing motion and set `linearVelocity` only for an instant change such as a jump. +- Cache `GetComponent()` once. Do not call `GetComponent`, `Find`, or `Camera.main` inside `Update`. + +```csharp +using UnityEngine; +using UnityEngine.InputSystem; + +public class Jumper : MonoBehaviour +{ + [SerializeField] private float jumpSpeed = 6f; + private Rigidbody body; + private bool jumpPressed; + + private void Awake() + { + body = GetComponent(); + } + + private void Update() + { + jumpPressed = Keyboard.current != null && Keyboard.current.spaceKey.wasPressedThisFrame; + } + + private void FixedUpdate() + { + if (!jumpPressed) return; + body.linearVelocity = new Vector3(body.linearVelocity.x, jumpSpeed, body.linearVelocity.z); + jumpPressed = false; + } +} +``` + +## Data and safety +- Expose designer fields with `[SerializeField] private`. Do not make gameplay fields public just so the Inspector can see them. +- Put tuneable numbers (damage, speeds, drop tables) on a ScriptableObject asset, not in a hardcoded constant inside a behaviour. +- Compare tags with `CompareTag("Player")`, not `tag == "Player"`. +- Null-check `Keyboard.current` and action references. They are null when the device is missing or the domain reloads. + +## Async and timing +- For waits, prefer `Awaitable` (`await Awaitable.WaitForSecondsAsync(1f)`) or a coroutine. Do not use `Thread.Sleep` or `Task.Delay` on the main thread. +- Unity objects are not thread-safe. Touch `Transform`, `GameObject`, and components only on the main thread. +- Check `this != null` after an `await`. The object may have been destroyed while the method was suspended. + +## Scenes and prefabs +- Do not write YAML into `.unity`, `.prefab`, or `.asset` files by hand. Change them in the editor or through an editor script. +- Load scenes by name or build index with `SceneManager.LoadSceneAsync`. Add the scene to the build profile first. +- Instantiate prefabs from a serialized reference, not `Resources.Load`, unless the project already uses Resources. + +## Done checklist +1. The Console shows no compile errors after the editor recompiles. +2. No obsolete-API warnings were introduced (`FindObjectOfType`, `velocity`, `Input.*`). +3. You said whether Play Mode was actually tested. + +--- + +Source: Loadout free Unity 6 pack (https://loadout-blush.vercel.app/packs/unity-6). Pinned to Unity 6.3 LTS (6000.3.x), last verified 2026-10-15. MIT License.