unity-csharp-guide
Installation
SKILL.md
Unity C# Practice Guide
Best practices for AI when generating C# for Unity. Unity is not plain .NET: the engine owns object lifetime, the main thread, serialization, and the AOT compiler. Most AI mistakes come from applying standard .NET patterns that the engine silently breaks.
Each #if UNITY_..._OR_NEWER guard marks an API that only exists from that version. When the target version is unknown, prefer the guarded (newer) API and keep the guard.
MonoBehaviour lifetime
Unity constructs, serializes, and destroys MonoBehaviour/ScriptableObject for you. Never use new, and never rely on constructors.
// NG: engine cannot attach this to a GameObject; fields stay null, Awake never runs
var enemy = new EnemyController();
// Warning: "You are trying to create a MonoBehaviour using the 'new' keyword.
// This is not allowed. MonoBehaviours can only be added using AddComponent()."
// OK: MonoBehaviour is added to a GameObject
var enemy = gameObject.AddComponent<EnemyController>();