Skip to content

manage_scriptable_object: value with JSON object ({guid}/{path}) silently clears ObjectReference instead of setting it #950

Closed

Description

@Art-Zloader

Description

When using manage_scriptable_object modify action to set an ObjectReference property, passing a JSON object (e.g. {"guid": "..."} or {"path": "..."}) via value silently clears the reference instead of setting it. The response reports success: true, ok: true with the message "Cleared reference.", giving no indication of failure.

This is a silent data loss bug — the caller believes the operation succeeded, but the reference was destroyed.

Two sub-issues

  1. Silent data loss: {"value": {"guid": "..."}} and {"value": {"path": "..."}} resolve newRef to null and clear the field without any error or warning.
  2. API inconsistency with manage_components: manage_components.set_property uses {"value": {"guid": "..."}} for object references. manage_scriptable_object requires {"ref": {"guid": "..."}} instead. This undocumented inconsistency makes it very easy for AI agents and users to use the wrong format.

Root Cause

In ManageScriptableObject.cs (lines 738–799), the ObjectReference handler reads the "ref" key from the patch object:

var refObj = patchObj["ref"] as JObject;        // ← reads "ref", not "value"
string refGuid = refObj?["guid"]?.ToString();
string refPath = refObj?["path"]?.ToString();

When the caller passes {"value": {"guid": "..."}}:

  • patchObj["ref"] is null → refObj is null
  • refGuid and refPath are both null
  • Falls through to the objRefValue?.Type == JTokenType.String check (line 766)
  • But objRefValue is a JObject, not a JTokenType.String → skip
  • newRef stays null → reference silently cleared

Reproduction

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

Setup: EnemyData ScriptableObject with [SerializeField] private GameObject _visualPrefab field.

Step 1: Set a known good value (baseline)

{
  "action": "modify",
  "target": {"path": "Assets/ScriptableObjects/Enemies/SkeletonSoldier_Mid.asset"},
  "patches": [{"path": "_visualPrefab", "ref": {"guid": "a18ddbbe71509274e9c0c45c6285e830"}}]
}

Result: "Set reference (ref.guid)." — File shows guid: a18ddbbe... ✅

Step 2: Overwrite with value object format

{
  "action": "modify",
  "target": {"path": "Assets/ScriptableObjects/Enemies/SkeletonSoldier_Mid.asset"},
  "patches": [{"path": "_visualPrefab", "value": {"guid": "a18ddbbe71509274e9c0c45c6285e830"}}]
}

Response: success: true, ok: true, message: "Cleared reference." — File shows fileID: 0 ❌

Step 3: Same with path format

{
  "patches": [{"path": "_visualPrefab", "value": {"path": "Assets/Prefabs/Enemies/Visuals/Enemy_SkeletonSoldier.prefab"}}]
}

Response: success: true, ok: true, message: "Cleared reference." — File shows fileID: 0 ❌

Step 4: Reproduced on a different SO and field

Tested ProfessionData._projectilePrefab on Archer.asset — same result: value + JSON object silently clears the reference.

Working formats (for reference)

Format Result
{"ref": {"guid": "xxx"}} ✅ Set reference
{"ref": {"path": "Assets/xxx.prefab"}} ✅ Set reference
{"value": "Assets/xxx.prefab"} (string) ✅ Set reference (path-shorthand)
{"value": "32-char-hex-guid"} (string) ✅ Set reference (guid-shorthand)
{"value": {"guid": "xxx"}} (object) ❌ Silently clears
{"value": {"path": "xxx"}} (object) ❌ Silently clears

Suggestions

  1. When value is a JObject containing guid or path keys, treat it as an object reference (same as ref), rather than silently resolving to null.

  2. At minimum, return ok: false with an error message like "value contains an object with guid/path keys — did you mean to use 'ref' instead of 'value'?" instead of silently clearing.

  3. Consider unifying the API with manage_components, which uses value: {"guid": "..."} for object references. The current inconsistency between tools is a usability trap.

Related

Activity

  1. Scriptwonder commented on Mar 23, 2026

    @Scriptwonder
    Collaborator

    Let me know if its fixed also, I tested with your cast and it works on my end.

  2. Art-Zloader commented on Mar 23, 2026

    @Art-Zloader
    Author

    Verified fixed in v9.6.1-beta.3.

    Re-tested the exact reproduction steps from the original report:

    Format v9.6.0 (broken) v9.6.1-beta.3 (fixed)
    {"value": {"guid": "a18ddbbe..."}} ❌ "Cleared reference." → fileID: 0 ✅ "Set reference to 'Enemy_SkeletonSoldier'." → guid preserved
    {"value": {"path": "Assets/Prefabs/..."}} ❌ "Cleared reference." → fileID: 0 ✅ "Set reference to 'Enemy_SkeletonSoldier'." → guid preserved

    No more silent data loss. The value key now correctly handles JSON objects with guid/path keys, consistent with manage_components behavior. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions