edit-scene
Installation
SKILL.md
Guide for creating and editing Unity scene files in Unity projects.
Rules
- Do not directly Edit or Write
.unityor.prefabfiles. Instead, write an editor script underAssets/Editor/and execute it in Unity to create or update the scene or prefab — those carry GameObject/Prefab-instance structure that is unsafe to author by hand. - Editor scripts must always end with
EditorSceneManager.SaveScene(orPrefabUtility.SaveAsPrefabAssetfor prefabs). Treat "no dirty scenes/assets at script exit" as a hard postcondition.- Scene:
EditorSceneManager.SaveScene(scene, path)(new) orEditorSceneManager.SaveScene(scene)(existing). The return value istrueon success. - Prefab:
PrefabUtility.SaveAsPrefabAsset(go, path). When editing viaLoadPrefabContents, always pair withSaveAsPrefabAsset→UnloadPrefabContents. - When the script also creates side-effect assets (Materials, ScriptableObjects, etc.), call
AssetDatabase.SaveAssets()after the per-object saves to flush pending writes.
- Scene:
- Before running an editor script, check if the editor is in Play Mode using the
unity_play_controltool. If it is, stop it first — Play Mode may skip recompilation, leaving stale code active. - After modifying code, confirm compilation success using the
get_unity_compilation_resulttool before running. - To determine which assembly an editor script belongs to, run
${CLAUDE_SKILL_DIR}/scripts/resolve-assembly.sh <cs-file-path>. It walks up directories to find the nearest.asmdef; if none is found, it falls back toAssembly-CSharp-Editor(path contains/Editor/) orAssembly-CSharp. - Prefer the
run_method_in_unitytool (MCP Server Extension for Unity) for execution. Define apublic staticmethod in the script (adding[MenuItem("Tools/...")]is optional) and invoke it directly viarun_method_in_unity. Only fall back toexecute_run_configurationor other alternatives whenrun_method_in_unityis unavailable. - For uGUI buttons and text, use the legacy variants (
UnityEngine.UI.Button/UnityEngine.UI.Text). Do not use TextMeshPro unless the user explicitly requests it. - Apply context-menu-equivalent defaults when creating uGUI components (see Resources below).