Skip to content

fix: replace Editor-only McpLog with Debug.LogWarning in Runtime asse…#535

Merged
dsarno merged 1 commit into
CoplayDev:mainfrom
dsarno:fix/runtime-mcplog-reference
Jan 8, 2026
Merged

fix: replace Editor-only McpLog with Debug.LogWarning in Runtime asse…#535
dsarno merged 1 commit into
CoplayDev:mainfrom
dsarno:fix/runtime-mcplog-reference

Conversation

@dsarno

@dsarno dsarno commented Jan 8, 2026

Copy link
Copy Markdown
Collaborator

…mbly

fixes #533

  • UnityTypeConverters.cs referenced McpLog (Editor-only) from Runtime asmdef
  • This caused CS0103 build errors in player builds
  • Replaced with UnityEngine.Debug.LogWarning for runtime compatibility

Also cleaned up test file:

  • Removed stale NL test artifacts (Build marker, Tail test comments)
  • Removed unused local functions causing CS8321 warnings

Summary by Sourcery

Replace editor-only logging with runtime-safe warnings and clean up obsolete test artifacts.

Bug Fixes:

  • Replace editor-only McpLog usage in runtime serialization with UnityEngine.Debug.LogWarning to prevent player build errors.

Tests:

  • Remove stale NL test markers and unused local helper functions from LongUnityScriptClaudeTest to eliminate CS8321 warnings and test noise.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced error handling for Unity object deserialization in runtime environments, improving stability when encountering unexpected data formats with graceful fallback behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

…mbly

- UnityTypeConverters.cs referenced McpLog (Editor-only) from Runtime asmdef
- This caused CS0103 build errors in player builds
- Replaced with UnityEngine.Debug.LogWarning for runtime compatibility

Also cleaned up test file:
- Removed stale NL test artifacts (Build marker, Tail test comments)
- Removed unused local functions causing CS8321 warnings
@sourcery-ai

sourcery-ai Bot commented Jan 8, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replaces an Editor-only logging call with a runtime-safe Debug.LogWarning in the Unity runtime assembly to fix player build errors, and cleans up obsolete test artifacts and unused local functions in a long test script to remove compiler warnings.

Sequence diagram for runtime deserialization warning in non-Editor mode

sequenceDiagram
    participant Caller
    participant UnityEngineObjectConverter
    participant UnityEngineDebug

    Caller->>UnityEngineObjectConverter: ReadJson(reader, objectType, existingValue)
    UnityEngineObjectConverter->>UnityEngineObjectConverter: Detect nonEditor runtime context
    UnityEngineObjectConverter->>UnityEngineDebug: LogWarning("UnityEngineObjectConverter cannot deserialize complex objects in non-Editor mode.")
    UnityEngineObjectConverter->>UnityEngineObjectConverter: Skip unsupported token
    UnityEngineObjectConverter-->>Caller: Return null or existingValue
Loading

Updated class diagram for UnityEngineObjectConverter logging behavior

classDiagram
    class UnityEngineObjectConverter {
        +ReadJson(reader, objectType, existingValue) UnityEngine.Object
        -HandleRuntimeDeserialization(reader) void
    }

    class UnityEngineDebug {
        +LogWarning(message) void
    }

    UnityEngineObjectConverter ..> UnityEngineDebug : uses
Loading

File-Level Changes

Change Details Files
Make runtime serialization logging compatible with non-Editor/player builds.
  • Replaced use of Editor-only McpLog.Warn with UnityEngine.Debug.LogWarning in the UnityEngineObjectConverter runtime deserialization path.
  • Left existing reader token-skipping logic intact so runtime behavior is unchanged aside from the logging mechanism.
MCPForUnity/Runtime/Serialization/UnityTypeConverters.cs
Clean up stale test scaffolding and remove unused local functions causing compiler warnings.
  • Removed obsolete NL test comments around Update() that were used as anchors/markers.
  • Deleted tail test marker comments and nested local helper functions that are no longer used, eliminating CS8321 warnings while preserving surrounding Pad0240 method structure.
TestProjects/UnityMCPTests/Assets/Scripts/LongUnityScriptClaudeTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#533 Ensure runtime (non-Editor) deserialization path in UnityTypeConverters.cs does not reference Editor-only McpLog, so that player builds compile without CS0103 errors.

Possibly linked issues

  • #(unlabeled): PR replaces Editor-only McpLog with Debug.LogWarning in UnityTypeConverters runtime path, directly resolving the issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jan 8, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This change fixes a bug where McpLog (an Editor-only class) was incorrectly called in runtime deserialization code. The fix replaces Editor-specific logging with UnityEngine.Debug.LogWarning() and refactors control flow to return immediately. Additionally, test scaffolding comments are removed.

Changes

Cohort / File(s) Summary
Serialization bug fix
MCPForUnity/Runtime/Serialization/UnityTypeConverters.cs
Replaced McpLog.Warn() with UnityEngine.Debug.LogWarning() in non-Editor deserialization path; added explicit JSON token consumption and immediate return of existingValue to resolve Editor-assembly reference in runtime code.
Test cleanup
TestProjects/UnityMCPTests/Assets/Scripts/LongUnityScriptClaudeTest.cs
Removed non-functional test anchor comments and placeholder scaffolding within Update() and Pad0240() methods.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Suggested labels

bug

Poem

🐰 A hop, a skip, a logging fix—
The Editor assembly no longer breaks at runtime mix!
We swap McpLog for Debug's bright call,
And clean the test dust from the hall.

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: replacing Editor-only McpLog with Debug.LogWarning in the Runtime assembly to fix build errors.
Linked Issues check ✅ Passed The pull request directly addresses issue #533 by replacing McpLog (Editor-only) with Debug.LogWarning in runtime code, eliminating CS0103 errors in player builds.
Out of Scope Changes check ✅ Passed All changes are in scope: McpLog replacement in UnityTypeConverters.cs for runtime compatibility, and cleanup of stale test artifacts in the test file.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
MCPForUnity/Runtime/Serialization/UnityTypeConverters.cs (1)

346-349: Consider simplifying token consumption.

The token consumption logic works, but could be more explicit and defensive.

♻️ Optional: More explicit token consumption
 UnityEngine.Debug.LogWarning("UnityEngineObjectConverter cannot deserialize complex objects in non-Editor mode.");
 // Skip the token to avoid breaking the reader
-if (reader.TokenType == JsonToken.StartObject) JObject.Load(reader);
-else if (reader.TokenType == JsonToken.String) reader.ReadAsString(); 
+if (reader.TokenType == JsonToken.StartObject)
+{
+    JObject.Load(reader); // Consume entire object
+}
+else
+{
+    reader.Read(); // Consume any other token (typically String)
+}
 // Return null or existing value, depending on desired behavior
 return existingValue;

This approach:

  • Uses reader.Read() for simple token consumption without processing the value
  • Handles any unexpected token type defensively (though only String/StartObject are expected)
  • More explicit about the intention to skip/consume
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf6603d and 71725dc.

📒 Files selected for processing (2)
  • MCPForUnity/Runtime/Serialization/UnityTypeConverters.cs
  • TestProjects/UnityMCPTests/Assets/Scripts/LongUnityScriptClaudeTest.cs
💤 Files with no reviewable changes (1)
  • TestProjects/UnityMCPTests/Assets/Scripts/LongUnityScriptClaudeTest.cs
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: dsarno
Repo: CoplayDev/unity-mcp PR: 260
File: UnityMcpBridge/UnityMcpServer~/src/server_version.txt:1-1
Timestamp: 2025-09-04T01:01:11.927Z
Learning: The UnityMcpBridge project is not maintaining changelogs yet, so don't suggest adding changelog entries for version bumps.
Learnt from: dsarno
Repo: CoplayDev/unity-mcp PR: 0
File: :0-0
Timestamp: 2025-09-03T16:00:55.839Z
Learning: ComponentResolver in UnityMcpBridge/Editor/Tools/ManageGameObject.cs is a nested static class within ManageGameObject, not a sibling type. The `using static MCPForUnity.Editor.Tools.ManageGameObject;` import is required to access ComponentResolver methods directly without the outer class qualifier.
Learnt from: msanatan
Repo: CoplayDev/unity-mcp PR: 491
File: MCPForUnity/Editor/Windows/EditorPrefs/EditorPrefsWindow.cs:78-115
Timestamp: 2025-12-29T15:23:17.871Z
Learning: In the MCPForUnity project, the team prefers to rely on their testing process to catch UI initialization issues rather than adding defensive null checks for UI elements in editor windows.
Learnt from: msanatan
Repo: CoplayDev/unity-mcp PR: 316
File: TestProjects/UnityMCPTests/Assets/Tests/EditMode/Resources.meta:1-8
Timestamp: 2025-10-13T13:27:23.040Z
Learning: UnityMcpBridge is a legacy project kept for backwards compatibility; MCPForUnity is the only active Unity plugin project. GUID collisions between UnityMcpBridge and MCPForUnity are acceptable.
🧬 Code graph analysis (1)
MCPForUnity/Runtime/Serialization/UnityTypeConverters.cs (3)
MCPForUnity/Editor/Helpers/ObjectResolver.cs (2)
  • UnityEngine (32-105)
  • UnityEngine (170-199)
MCPForUnity/Editor/Helpers/PropertyConversion.cs (1)
  • UnityEngine (76-90)
MCPForUnity/Editor/Helpers/McpLog.cs (1)
  • Debug (31-35)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Sourcery review
🔇 Additional comments (1)
MCPForUnity/Runtime/Serialization/UnityTypeConverters.cs (1)

344-344: Correct fix for the runtime build error.

Replacing McpLog.Warn with UnityEngine.Debug.LogWarning successfully resolves the CS0103 error by using a runtime-compatible logging API. The warning message clearly communicates the limitation.

@dsarno dsarno merged commit 7d58053 into CoplayDev:main Jan 8, 2026
1 of 2 checks passed
@dsarno dsarno deleted the fix/runtime-mcplog-reference branch January 15, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error McpLog in not Editor codes

1 participant