agentleFS
KonHKonH/GlobalStrategy/.claude/skills/unity-scenes/SKILL.md

unity-scenes

Skill3 starsChanged 2 months agoMITView on GitHub

Authoring reference for Unity scene files (.unity YAML) — the MCP tool workflow, the hand-edit fallback (fileID generation, PrefabInstance blocks, SceneRoots), build registration in EditorBuildSettings.asset, and the silent-null gotcha when a new [SerializeField] is added to a MonoBehaviour already placed in a scene. Load before creating, editing, registering, or debugging any .unity scene file.

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 2 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Prefab instances in a scene: use !u!1001 PrefabInstance blocks:

    line 27
  2. Distinctive:

    When Unity Editor is connected via UnityMCP, use MCP tools instead of hand-editing YAML:

    line 55
  3. Very specific:

    Every object in a scene needs a unique positive integer fileID.

    line 74
  4. Very specific:

    Add {fileID: <new-fileID>} to SceneRoots.m_Roots.

    line 131
  5. Very specific:

    Add the Transform fileID to SceneRoots.m_Roots for root objects

    line 145
  6. Very specific:

    Delete its PrefabInstance block and remove its fileID from SceneRoots.m_Roots.

    line 153
  7. Very specific:

    When a [SerializeField] field is added to a C# class that is already instantiated in a scene, Unity does not auto-populate the field in the …

    line 172
  8. Distinctive:

    Always verify by searching the scene YAML for the field name before assuming it is assigned.

    line 188

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Scene Format and Registration

File Format

Scene files (.unity) are Unity YAML files (%YAML 1.1). They must be created through the Unity Editor. Structure:

Fixed header objects (always present, fileIDs 1–4):

  • !u!29 &1 — OcclusionCullingSettings
  • !u!104 &2 — RenderSettings
  • !u!157 &3 — LightmapSettings
  • !u!196 &4 — NavMeshSettings

Scene content — GameObjects, components, and prefab instances with large random fileIDs.

Prefab instances in a scene use !u!1001 PrefabInstance blocks:

--- !u!1001 &<fileID>
PrefabInstance:
  m_Modification:
    m_TransformParent: {fileID: 0}          # 0 = root; or fileID of parent Transform
    m_Modifications:
    - target: {fileID: <obj-fileID>, guid: <prefab-guid>, type: 3}
      propertyPath: m_LocalPosition.x
      value: 0
      objectReference: {fileID: 0}
    m_RemovedComponents: []
    m_RemovedGameObjects: []
    m_AddedGameObjects: []
    m_AddedComponents: []
  m_SourcePrefab: {fileID: 100100000, guid: <prefab-guid>, type: 3}

SceneRoots (always the last object, fileID 9223372036854775807) lists the fileIDs of all root-level Transform/PrefabInstance objects:

--- !u!1660057539 &9223372036854775807
SceneRoots:
  m_Roots:
  - {fileID: <transform-or-prefabinstance-fileID>}

MCP Workflow (preferred)

When Unity Editor is connected via UnityMCP, use MCP tools instead of hand-editing YAML:

  • Inspect scene: manage_scene (action get_hierarchy) or mcpforunity://scene/gameobject-api
  • Add prefab instance: manage_gameobject (action create, param prefab_path)
  • Add plain GameObject: manage_gameobject (action create)
  • Modify object: manage_gameobject (action modify) or manage_components (action set_property)
  • Remove object: manage_gameobject (action delete)
  • Save scene: manage_scene (action save)

Scene registration in EditorBuildSettings.asset has no MCP tool — edit that file directly (see Scene Registration section below).

Fall back to the manual YAML workflow below only when MCP is unavailable.

Modifying Scenes via Text

Scene files can be modified by hand if the rules below are followed precisely.

FileID generation

Every object in a scene needs a unique positive integer fileID. When adding new objects, pick a large random integer (e.g. 9 digits) that does not collide with any existing &fileID anchor in the file. FileIDs 1–4 are reserved for the header objects.

Adding a prefab instance

  1. Get the prefab's GUID from its .meta file.
  2. Get the fileIDs of the prefab's internal objects from the .prefab file (needed for m_Modifications targets).
  3. Choose a new unique fileID for the PrefabInstance block.
  4. Append the block before SceneRoots:
--- !u!1001 &<new-fileID>
PrefabInstance:
  m_ObjectHideFlags: 0
  serializedVersion: 2
  m_Modification:
    serializedVersion: 3
    m_TransformParent: {fileID: 0}
    m_Modifications:
    - target: {fileID: <root-transform-fileID-in-prefab>, guid: <prefab-guid>, type: 3}
      propertyPath: m_LocalPosition.x
      value: 0
      objectReference: {fileID: 0}
    - target: {fileID: <root-transform-fileID-in-prefab>, guid: <prefab-guid>, type: 3}
      propertyPath: m_LocalPosition.y
      value: 0
      objectReference: {fileID: 0}
    - target: {fileID: <root-transform-fileID-in-prefab>, guid: <prefab-guid>, type: 3}
      propertyPath: m_LocalPosition.z
      value: 0
      objectReference: {fileID: 0}
    - target: {fileID: <root-transform-fileID-in-prefab>, guid: <prefab-guid>, type: 3}
      propertyPath: m_LocalRotation.x
      value: 0
      objectReference: {fileID: 0}
    - target: {fileID: <root-transform-fileID-in-prefab>, guid: <prefab-guid>, type: 3}
      propertyPath: m_LocalRotation.y
      value: 0
      objectReference: {fileID: 0}
    - target: {fileID: <root-transform-fileID-in-prefab>, guid: <prefab-guid>, type: 3}
      propertyPath: m_LocalRotation.z
      value: 0
      objectReference: {fileID: 0}
    - target: {fileID: <root-transform-fileID-in-prefab>, guid: <prefab-guid>, type: 3}
      propertyPath: m_LocalRotation.w
      value: 1
      objectReference: {fileID: 0}
    - target: {fileID: <root-gameobject-fileID-in-prefab>, guid: <prefab-guid>, type: 3}
      propertyPath: m_Name
      value: MyInstance
      objectReference: {fileID: 0}
    m_RemovedComponents: []
    m_RemovedGameObjects: []
    m_AddedGameObjects: []
    m_AddedComponents: []
  m_SourcePrefab: {fileID: 100100000, guid: <prefab-guid>, type: 3}
  1. Add {fileID: <new-fileID>} to SceneRoots.m_Roots.

To set position to something other than origin, change the value fields for m_LocalPosition.*.

To override a serialized field on a component inside the prefab, add a m_Modifications entry pointing to that component's fileID and propertyPath matching the C# field name.

To parent the instance under another GameObject's Transform, set m_TransformParent: {fileID: <parent-transform-fileID>} and do not add it to SceneRoots.

Adding a plain GameObject

Requires three blocks: GameObject (!u!1), Transform (!u!4), and any components. Each gets its own unique fileID. Cross-references:

  • GameObject.m_Component lists all component fileIDs
  • Transform.m_GameObject points to its GameObject
  • Transform.m_Father: {fileID: 0} for root objects
  • Add the Transform fileID to SceneRoots.m_Roots for root objects

Modifying an existing object

Edit the value directly in the relevant block. For prefab instances, only change value fields inside m_Modifications — do not change target.fileID or target.guid.

Removing a prefab instance

Delete its PrefabInstance block and remove its fileID from SceneRoots.m_Roots.

Scene Registration

To include a scene in the build, add it to ProjectSettings/EditorBuildSettings.asset:

m_Scenes:
- enabled: 1
  path: Assets/Scenes/Feature/SceneName.unity
  guid: <scene-guid>
  • guid comes from the scene's .meta file (guid: field)
  • Scenes not listed here are excluded from builds (but can still be loaded by path in the Editor)
  • Order in m_Scenes determines the build index used by SceneManager.LoadScene(int)

New [SerializeField] fields on existing scene MonoBehaviours

When a [SerializeField] field is added to a C# class that is already instantiated in a scene, Unity does not auto-populate the field in the scene YAML. It stays absent, which means the field is null/default at runtime — silently, with no error.

To wire it up without opening the Unity Editor, add the field line directly to the MonoBehaviour block in the .unity YAML:

--- !u!114 &<fileID>
MonoBehaviour:
  ...
  _existingField: {fileID: 4900000, guid: <existing-guid>, type: 3}
  _newField: {fileID: 4900000, guid: <new-asset-guid>, type: 3}   # add this
  • fileID: 4900000 is the standard fileID for TextAsset references
  • type: 3 means a regular imported asset
  • The guid comes from the asset's .meta file

Always verify by searching the scene YAML for the field name before assuming it is assigned.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.