Skip to content

manage_components / manage_prefabs: Setting Sprite sub-asset references fails with path/guid — undocumented spriteName workaround required #949

@Art-Zloader

Description

@Art-Zloader

Description

When setting a Sprite property on a component (e.g., SpriteRenderer.m_Sprite or a custom [SerializeField] private Sprite _icon), standard object reference formats (path, guid, raw string) all fail because they resolve to the main Texture2D asset instead of the Sprite sub-asset.

The code in ComponentOps.cs (lines 645–686) does support Sprite sub-asset resolution via {"guid": "...", "spriteName": "..."} and {"guid": "...", "fileID": ...}, but this is completely undocumented — not in tool descriptions, README, or any MCP server instructions.

Reproduction

Environment: unity-mcp v9.6.0, Unity 6000.3.10f1

Test 1: manage_components with path (FAILS)

{
  "action": "set_property",
  "target": "MyObject",
  "component_type": "SpriteRenderer",
  "property": "m_Sprite",
  "value": {"path": "Assets/Textures/Thumbnails/Icon_Gold.png"}
}

Error: Object 'Icon_Gold' (type: Texture2D) is not compatible with the property type.

Test 2: manage_components with guid only (FAILS)

{
  "value": {"guid": "ac7591592e65db74f8b9b62e029339ef"}
}

Error: Same — resolves to Texture2D.

Test 3: manage_components with raw string path (FAILS)

{
  "value": "Assets/Textures/Thumbnails/Icon_Gold.png"
}

Error: Same.

Test 4: manage_components with guid + spriteName (WORKS)

{
  "value": {"guid": "ac7591592e65db74f8b9b62e029339ef", "spriteName": "Icon_Gold"}
}

Result: Success.

Test 5: manage_prefabs — same pattern

modify_contents with component_properties shows the same behavior: path and guid alone fail; guid + spriteName works.

Root Cause

In ComponentOps.cs, the SetObjectReference() method:

  • Lines 645–660: guid + spriteName → uses LoadAllAssetsAtPath to find Sprite by name ✅
  • Lines 663–686: guid + fileID → matches by fileID ✅
  • Line 688: guid alone → LoadAssetAtPath<Object>(path) → returns Texture2D ❌
  • Line 696: path alone → LoadAssetAtPath<Object>(path) → returns Texture2D ❌

Suggestions

  1. Auto-fallback for Sprite properties: When path or guid resolves to Texture2D but the target SerializedProperty expects Sprite, automatically try LoadAllAssetsAtPath and pick the first matching Sprite sub-asset (covers the common single-sprite-per-texture case).

  2. Improve error message: Instead of just "type: Texture2D is not compatible", suggest: "Tip: For Sprite sub-assets, use {"guid": "...", "spriteName": "..."} format."

  3. Document the spriteName and fileID fields in the tool descriptions for manage_components and manage_prefabs, and in the MCP server instructions sent to AI clients.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions