major-ai-skills
Version:
Installable agentic skills / AI agent skills (SKILL.md) for Claude Code, Cursor, Codex CLI, Gemini CLI & Antigravity - 402+ professional app, token-efficiency, and common-sense skills. SEO/GEO ready.
146 lines (119 loc) • 6.9 kB
Markdown
---
name: unity
description: "Automate Unity editor and runtime workflows with C#, Addressables, render pipelines, and batch builds."
category: game-engines
risk: safe
source: self
source_type: self
date_added: "2026-08-26"
tags: ["unity", "csharp", "editor-scripting", "urp", "addressables", "batchmode", "claude"]
tools: ["claude", "cursor", "gemini", "codex"]
---
Unity is a component-driven real-time engine with a **C
```
┌─────────────────────────────────────────────────────────────┐
│ Unity Engine Architecture │
│ │
│ Authoring (Editor) │
│ ├── UnityEditor APIs (MenuItem, EditorWindow, AssetDatabase│
│ ├── Importers, BuildPipeline, ScriptableBuildPipeline │
│ └── Domain Reload / Enter Play Mode Options │
│ │
│ Runtime (Player) │
│ ├── GameObject + MonoBehaviour / ScriptableObject │
│ ├── SceneManager, Physics, Animation, UI Toolkit/uGUI │
│ └── URP/HDRP Render Pipeline Asset │
│ │
│ Content & CI │
│ ├── Addressables / AssetBundles │
│ ├── Unity -batchmode -projectPath -executeMethod │
│ └── IL2CPP / Mono scripting backends │
└─────────────────────────────────────────────────────────────┘
```
---
## Operational Capabilities & Agent Directives
1. **Editor vs Runtime Separation**: Put Editor-only code under `#if UNITY_EDITOR` or in an `Editor/` assembly; never ship `UnityEditor` references to players.
2. **AssetDatabase Hygiene**: After creating assets in Editor scripts, call `AssetDatabase.CreateAsset`, `SaveAssets`, and `Refresh` in the correct order.
3. **Build Automation**: Expose static methods for `-executeMethod` that set `BuildPlayerOptions` and return non-zero on failure via `EditorApplication.Exit(code)`.
4. **Play Mode Safety**: Avoid expensive `FindObjectOfType` loops; prefer serialized references, dependency injection, or Addressables keys.
5. **Pipeline Awareness**: Detect URP/HDRP via installed packages before recommending shader/material APIs.
---
Save as `Assets/Editor/BuildPlayerMenu.cs`:
```csharp
// ==============================================================================
// Unity Editor: menu item + CI -executeMethod build entry
// ==============================================================================
using System.IO;
using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEngine;
public static class BuildPlayerMenu
{
[]
public static void BuildWindowsFromMenu()
{
var ok = BuildWindowsInternal();
if (!ok) Debug.LogError("Windows build failed.");
}
// Unity.exe -batchmode -quit -projectPath <path> -executeMethod BuildPlayerMenu.BuildWindowsCI
public static void BuildWindowsCI()
{
var ok = BuildWindowsInternal();
EditorApplication.Exit(ok ? 0 : 1);
}
static bool BuildWindowsInternal()
{
var outDir = Path.Combine("Builds", "Windows");
Directory.CreateDirectory(outDir);
var options = new BuildPlayerOptions
{
scenes = GetEnabledScenes(),
locationPathName = Path.Combine(outDir, "Game.exe"),
target = BuildTarget.StandaloneWindows64,
options = BuildOptions.CompressWithLz4HC
};
var report = BuildPipeline.BuildPlayer(options);
var summary = report.summary;
Debug.Log($"Build result: {summary.result} size={summary.totalSize}");
return summary.result == BuildResult.Succeeded;
}
static string[] GetEnabledScenes()
{
var scenes = EditorBuildSettings.scenes;
var enabled = new System.Collections.Generic.List<string>();
foreach (var s in scenes)
if (s.enabled) enabled.Add(s.path);
return enabled.ToArray();
}
}
```
---
| Issue & Failure Signature | Root Cause Analysis | Diagnostic & Resolution Pathway |
| :--- | :--- | :--- |
| **`UnityEditor` missing in player build** | Editor script not under `Editor/` folder or asmdef. | Move to `Assets/**/Editor/` or Editor-only asmdef with `includePlatforms: Editor`. |
| **Batchmode hangs after build** | Missing `-quit` or open modal dialog. | Always pass `-quit`; avoid `EditorUtility.DisplayDialog` in CI paths. |
| **NullReference on serialized field** | Prefab/scene reference lost after reimport. | Reassign in Inspector; prefer `SerializeField` + validation `OnValidate`. |
| **Slow Enter Play Mode** | Domain reload + AssetDatabase thrash. | Enable Enter Play Mode Options; reduce static mutable state. |
---
```bash
Unity.exe -batchmode -nographics -quit ^
-projectPath "C:\work\MyGame" ^
-executeMethod BuildPlayerMenu.BuildWindowsCI ^
-logFile "C:\work\MyGame\Builds\build.log"
```
- **Project**: `Assets/`, `Packages/manifest.json`, `ProjectSettings/`
- **Library (generated)**: `Library/` - safe to delete to force reimport
- **Logs**: Editor.log under local AppData Unity folders
---
> **MANDATORY**: Isolate Editor code from runtime assemblies. For CI, use `-batchmode -quit -executeMethod` with explicit exit codes. Prefer serialized references over scene searches in production gameplay code.