Unity C# code conventions — naming, no-hardcoded-values, shared constants, DOTS-specific rules, editor script standards, anti-patterns. Use when writing or reviewing Unity C# code.
| Element | Casing | Example |
|---|
| Namespace | PascalCase | DOTSCombat |
| Class, Struct | PascalCase | AttackTimerSystem |
| Interface | IPascalCase | IHealthProvider |
| Enum | PascalCase | AttackType |
| Enum member | PascalCase | AttackType.Ranged |
| Public method | PascalCase | CalculateDamage() |
| Private method | PascalCase | ApplyKnockback() |
| Property | PascalCase | MaxHealth |
| Public field | PascalCase | DamageMultiplier |
| Private field | camelCase | attackTimer |
| Parameter | camelCase | targetEntity |
| Local variable | camelCase | closestEnemy |
Constant (const) | PascalCase | MaxStackCount |
| Static readonly | PascalCase | DefaultColor |
| Type parameter | TPascalCase | TComponent |
| Element | Pattern | Example |
|---|---|---|
| MonoBehaviour | Noun/NounPhrase | PlayerController |
| IComponentData | Domain suffix | HealthData, AttackTimer |
| Tag component | Is prefix or no suffix | IsMoving, Dead |
| ISystem | Verb + System | AttackTimerSystem |
| Baker | Authoring + Baker | class HealthBaker : Baker<HealthAuthoring> |
| Authoring | Authoring suffix | HealthAuthoring |
| IAspect | Aspect suffix | CombatAspect |
| ScriptableObject | Noun | ArenaConfig |
| Editor script | Descriptive verb/noun | BattlefieldAssemblySetup |
| Test class | Tests suffix | AttackTimerSystemTests |
Packages/): NEVER use game/demo names. Types must be generic and reusable across games.
ColorFitGameState, BackpackResult, BattleDemoPhaseQueuePuzzleGameState, GridFillSystem, CharacterMovementSystemAssets/Demos/): Game-specific names are fine here (ColorFitCanvasUI, BattleDemoSceneSetup)AttackTimerSystem.csEditor/ folder with Editor-only asmdef"Universal Render Pipeline/Lit" → ShaderConstants.UrpLit"_BaseMap" → ShaderConstants.PropBaseMap"BattlefieldArena" → private const string ArenaRootName"Assets/Prefabs/" → private const string PrefabFolderAcceptable inline strings: Debug.Log(), [MenuItem("...")] attributes, nameof(), one-time errors.
-1 sentinel → private const int InvalidIndex = -1;0.1f threshold → private const float DamageThreshold = 0.1f;2450 render queue → private const int AlphaTestRenderQueue = 2450;→ See references/constants-patterns.md for the full SharedConstants class pattern and file-local private const usage.
const, static readonly).asmdefEditor/ folder)UNITY_INCLUDE_TESTS define constraintPackages/[pkg]/Runtime/Combat/ → [Namespace].Combat[YourPackage].Editor | Tests: [YourNamespace].TestsIComponentDatastring, class, List<T>) — use FixedString32Bytes/FixedString64Bytesstruct Dead : IComponentData {})EnableableComponent over add/remove for frequent state changesISystem (struct) over SystemBase (class) for Burst compatibility[BurstCompile] on struct AND all lifecycle methods[RequireMatchingQueriesForUpdate] to skip when no matching entitiesComponentLookup<T> in OnCreate, update in OnUpdateSystemAPI.Time.ElapsedTime before foreach loops[UpdateInGroup(typeof(SimulationSystemGroup))]
[UpdateAfter(typeof(DetectionSystem))]
[UpdateBefore(typeof(NavigationSystemGroup))]
→ See references/anti-patterns.md for the full anti-patterns table (10 patterns with correct alternatives).
"Tools/[Package]/[Action]" — must be compile-time string literalAssetDatabase.LoadAssetAtPath<T>(path)Object.DestroyImmediate(tempGo)AssetDatabase.SaveAssets() + EditorSceneManager.SaveScene()| File | Content |
|---|---|
references/constants-patterns.md | SharedConstants class, private const, naming prefixes |
references/anti-patterns.md | Common anti-patterns table with correct alternatives |