Skip to content
Back to skills

Unity Csharp

ASecurity

Use for any task that writes, fixes or reviews Unity C# (MonoBehaviour, ScriptableObject, editor scripts), including tracking down runtime exceptions such as MissingReferenceException or InvalidOperationException from UnityEngine.Input, CS0618, CS0246 or CS0234 errors, "Missing script", and code that works in one Unity version but not another. Writes code for the project's actual Unity version, input settings and packages, and lints scripts for Unity 6 renames (Rigidbody.velocity to linearVel...

  • 3 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added November 29, 2026
developmentpythongoc#bashapi

Works with

  • api
  • mcp

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add flxnsee/gamedev-toolkit --skill unity-csharp --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Unity Csharp?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Unity Csharp
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/flxnsee-unity-csharp/badge)](https://www.skillsdirectory.com/skills/flxnsee-unity-csharp)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: unity-csharp
description: Use for any task that writes, fixes or reviews Unity C# (MonoBehaviour, ScriptableObject, editor scripts), including tracking down runtime exceptions such as MissingReferenceException or InvalidOperationException from UnityEngine.Input, CS0618, CS0246 or CS0234 errors, "Missing script", and code that works in one Unity version but not another. Writes code for the project's actual Unity version, input settings and packages, and lints scripts for Unity 6 renames (Rigidbody.velocity to linearVelocity, PhysicMaterial to PhysicsMaterial, FindObjectOfType), Unity 6 API in older projects, legacy Input calls when only the Input System is enabled, Cinemachine 2 vs 3, missing packages, `?.` and `??` on Unity objects, `new` on MonoBehaviours, class/file name mismatches, and GetComponent, Find or physics in Update. Covers lifecycle order, serialization, Rigidbody movement, ScriptableObjects and coroutines vs Awaitable.
license: MIT
compatibility: Python 3.10+, standard library only. Unity itself is not required. Rules cover Unity 2021.3 LTS through Unity 6.
metadata:
  author: gamedev-toolkit
  version: "0.1.0"
---

# Unity C#

Unity changed a lot between 2021 and Unity 6, and most C# online targets older versions.
**Before writing code, find out what this project is:**

| Read | Tells you |
| --- | --- |
| `ProjectSettings/ProjectVersion.txt` (`m_EditorVersion`) | `6000.x` = Unity 6, `2022.3` / `2021.3` = older LTS. Decides the API names |
| `ProjectSettings/ProjectSettings.asset` (`activeInputHandler`) | `0` = old Input Manager, `1` = Input System only, `2` = both |
| `Packages/manifest.json` and `packages-lock.json` | Which packages (and major versions) exist: Input System, Cinemachine 2 or 3, URP/HDRP, TextMeshPro |
| Existing scripts | Namespace and naming style, `[SerializeField] private` vs public fields, assembly layout |

Then write code for that version, and run the linter on what you wrote.

## Run the linter

`${CLAUDE_SKILL_DIR}` is this skill's folder, where its scripts are. Run the commands from the
project folder as shown, without searching for the script. If the variable was not filled
in, use the base directory shown when the skill loaded.

```bash
python "${CLAUDE_SKILL_DIR}/scripts/unity_csharp_lint.py" path/to/UnityProject             # whole project
python "${CLAUDE_SKILL_DIR}/scripts/unity_csharp_lint.py" . --only Assets/Scripts/Player.cs  # just the files you changed
python "${CLAUDE_SKILL_DIR}/scripts/unity_csharp_lint.py" . --json
```

Exit code `0` = no errors, `1` = errors, `2` = not a Unity project. `Assets/Plugins/` is
skipped unless you pass `--include-plugins`. Code inside version guards
(`#if UNITY_6000_0_OR_NEWER`) or `#if ENABLE_LEGACY_INPUT_MANAGER` is treated as deliberate.
Each finding names the file and line and says how to fix it.

Present errors first. Fix errors and warnings in code you wrote; for existing code, list them
and ask before changing files the user didn't mention. For `missing-package`, ask before
adding a package.

## Rules the linter can't check

1. **Serialization**: `[SerializeField] private float speed = 5f;`, not public fields. Unity
   doesn't serialize properties (use `[field: SerializeField]`), static fields, `Dictionary`,
   or interface-typed fields (use `[SerializeReference]`).
2. **Renaming a serialized field loses its Inspector values** in every scene and prefab.
   Keep them with `[FormerlySerializedAs("oldName")]` (`UnityEngine.Serialization`).
3. **Lifecycle**: `Awake` (own setup, cache components) → `OnEnable` (subscribe) → `Start`
   (talk to other objects) → `FixedUpdate` (physics) → `Update` (input, logic) → `LateUpdate`
   (cameras) → `OnDisable` (unsubscribe). Every `+=` in `OnEnable` needs a `-=` in `OnDisable`.
4. **Unity objects and null**: a destroyed object compares `== null` but isn't C# null. Write
   `if (target != null)` or `if (target)`, never `?.`/`??` on a `UnityEngine.Object`.
   `GetComponent<T>() ?? AddComponent<T>()` is a classic bug: use `TryGetComponent`.
5. **Physics in `FixedUpdate`**, input in `Update`. Move rigidbodies with forces, velocity or
   `MovePosition`, not `transform.position` (that teleports and skips collisions). Turn on
   Rigidbody interpolation for anything the camera follows.
6. **Frame-rate independence**: smooth with `Vector3.Lerp(a, b, 1f - Mathf.Exp(-sharpness * Time.deltaTime))`,
   not `Lerp(a, b, 0.1f)`.
7. **Editor-only code** (`using UnityEditor;`) goes in an `Editor` folder or assembly, or
   inside `#if UNITY_EDITOR`. The `unity-asmdef-graph` skill checks this.
8. **Static state survives Play mode when Domain Reload is off.** Reset statics in a
   `[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]` method.
9. **ScriptableObject changes made in Play mode persist** in the Editor. Don't keep runtime
   state in them unless you reset it.
10. **Unity API is main-thread only.** After `await Awaitable.BackgroundThreadAsync()`, come
    back with `await Awaitable.MainThreadAsync()`. Don't await the same `Awaitable` twice.

## After writing code

1. Run `python "${CLAUDE_SKILL_DIR}/scripts/unity_csharp_lint.py" . --only <files you changed>` and fix what it reports.
2. If Unity is installed and the editor is closed, the `unity-batchmode` skill's compile check
   proves it compiles. If a Unity MCP server is connected, ask it to refresh assets and read the
   console instead.
3. New scripts get `.meta` files the next time Unity focuses. Remind the user to commit them.

## Reference

- [references/versions.md](references/versions.md): old and Unity 6 API names, Cinemachine 2
  and 3. Read it before writing code for a version you're unsure of.
- [references/input-and-movement.md](references/input-and-movement.md): Input System polling
  and actions, old `Input` calls and their replacements, Rigidbody and CharacterController
  movement. Read it when writing input or movement code.
- [references/data-events-async.md](references/data-events-async.md): ScriptableObjects,
  events, coroutines and `Awaitable`. Read it when writing data, events or async code.

Files in this skill

  • SKILL.md14.3 KB
  • scripts/unity_csharp_lint.py32.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.