Skip to content

Feat/optional physics screencapture modules#1208

Open
ArkTarusov wants to merge 5 commits into
CoplayDev:betafrom
ArkTarusov:feat/optional-physics-screencapture-modules
Open

Feat/optional physics screencapture modules#1208
ArkTarusov wants to merge 5 commits into
CoplayDev:betafrom
ArkTarusov:feat/optional-physics-screencapture-modules

Conversation

@ArkTarusov

@ArkTarusov ArkTarusov commented Jun 16, 2026

Copy link
Copy Markdown

Description

9.7.1 made MCP for Unity hard-depend on three built-in modules (Physics, Physics 2D,
Screen Capture): UnityPhysicsCompat.cs uses typeof(Physics)/typeof(Physics2D) and
several editor tools reference Physics/Physics2D/ScreenCapture types directly, so the
package fails to compile when any of those modules is disabled (#1172). They were also
added as hard package.json dependencies, which force-pulls them into every consuming
project — undesirable for an editor-focused package. This PR makes all three modules
optional via versionDefines (the approach proposed in the issue) and removes the forced
dependencies.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Test update

Changes Made

  • Added versionDefines to MCPForUnity.Editor.asmdef and MCPForUnity.Runtime.asmdef
    (mirroring the existing UNITY_VFX_GRAPH): MCP_HAS_PHYSICS, MCP_HAS_PHYSICS_2D,
    MCP_HAS_SCREEN_CAPTURE, resolved from com.unity.modules.physics,
    com.unity.modules.physics2d, com.unity.modules.screencapture.
  • Runtime/Helpers/UnityPhysicsCompat.cs: resolve Physics/Physics2D via reflection
    (Type.GetType(...)) instead of typeof, so the shim compiles with the modules absent
    (no #if; consistent with the file's existing reflection design).
  • Runtime/Helpers/ScreenshotUtility.cs: guarded all ScreenCapture call sites behind
    MCP_HAS_SCREEN_CAPTURE, falling back to camera-based capture when absent.
  • Guarded all Physics/Physics2D usage in the editor tools behind the defines:
    Editor/Tools/Physics/* (incl. ManagePhysics returning a clear "module not installed"
    message), plus incidental usages in ManageScene, ManageAsset, Helpers/ComponentOps,
    Helpers/GameObjectSerializer, Tools/GameObjects/GameObjectComponentHelpers.
    3D and 2D physics are handled independently.
  • Removed com.unity.modules.physics, com.unity.modules.physics2d and
    com.unity.modules.screencapture from package.json dependencies so they are no
    longer force-pulled. (imageconversion, uielements, unitywebrequest, animation
    are genuinely used and kept.)

Compatibility / Package Source

  • Unity version(s) tested:
    • 2021.3.45f2 — batch-mode compile of TestProjects/UnityMCPTests in all four module
      combinations (both / none / 3D-only / 2D-only): 0 compile errors, both package
      assemblies build in every case.
    • 6000.0.60f1 — verified live in a real 2D project (physics2d present, physics +
      screencapture absent): the package no longer pulls the modules in and compiles cleanly.
  • Package source used: file: (local checkout of this branch). Reviewers can also point at
    https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity#feat/optional-physics-screencapture-modules.
  • Resolved commit hash from Packages/packages-lock.json (if using a Git package URL):
    6b1eb3bd6906d480aeca36353a8b20e3a7309fe3

Testing/Screenshots/Recordings

  • Python tests (cd Server && uv run pytest tests/ -v)
  • Unity EditMode tests
  • Unity PlayMode tests
  • Package import/compile check
  • Not applicable (explain why in Additional Notes)

Documentation Updates

  • I have added/removed/modified tools or resources
  • If yes, I have updated all documentation files using:
    • The LLM prompt at tools/UPDATE_DOCS_PROMPT.md (recommended)
    • Manual review of the generated changes

Related Issues

Fixes #1172

Additional Notes

  • No behavior change when the modules are present: the guards are inert and the
    UnityPhysicsCompat reflection resolves to the same types, so manage_physics and
    screenshots behave exactly as before. Graceful degradation only kicks in when a module
    is actually disabled.
  • No tool/resource API surface changed (same actions/parameters), so no docs update needed.
  • Python tests not applicable — this change is C#/asmdef/package.json only, no Python files
    touched.
  • EditMode/PlayMode tests not run locally; the change is inert with modules present (the CI
    configuration), and correctness with modules absent is covered by the compile matrix
    above. CI will exercise the full EditMode suite.
  • Not module dependencies (intentionally left untouched): ProfilerCategory.Physics /
    Physics2D (Profiling module) and a "Rigidbody" string-literal check in ManageScript.

Summary by CodeRabbit

Release Notes

  • Chores / Improvements

    • Enhanced support for optional Unity modules (Physics 3D, Physics 2D, Screen Capture) so unavailable features are excluded cleanly.
    • Added module-based build symbols for both editor and runtime for consistent feature availability.
    • Improved physics module handling by using runtime compatibility when Unity physics types may be missing.
  • Bug Fixes

    • Physics commands and screenshot/capture workflows now fail gracefully with clear “module not installed/unavailable” errors instead of crashes.
    • Updated guidance to require dimension: "2d" when 3D physics isn’t installed.
    • Documentation updated for manage_physics, manage_ui, and screenshot module optionality.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c0b1d46b-886f-4d13-9c56-c7eb1f61cfa6

📥 Commits

Reviewing files that changed from the base of the PR and between d30bbc4 and e8c45a0.

📒 Files selected for processing (2)
  • MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs
  • MCPForUnity/package.json
✅ Files skipped from review due to trivial changes (1)
  • MCPForUnity/package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs

📝 Walkthrough

Walkthrough

Adds compile-time module symbols for optional Unity Physics, Physics2D, and Screen Capture support, gates editor/runtime physics and capture code on those symbols, switches runtime physics type lookup to reflection, and updates tool docs to describe module-dependent behavior and errors.

Optional Unity Module Compile Guards

Layer / File(s) Summary
Assembly symbols and runtime physics compatibility
MCPForUnity/Editor/MCPForUnity.Editor.asmdef, MCPForUnity/Runtime/MCPForUnity.Runtime.asmdef, MCPForUnity/package.json, MCPForUnity/Runtime/Helpers/UnityPhysicsCompat.cs
Both asmdef files add versionDefines for Physics, Physics2D, and Screen Capture modules. UnityPhysicsCompat now resolves Physics and Physics2D types at runtime through cached Type lookups and uses nullable reflection probes instead of compile-time typeof(...) references.
Editor physics command guards
MCPForUnity/Editor/Tools/Physics/ManagePhysics.cs, MCPForUnity/Editor/Helpers/ComponentOps.cs, MCPForUnity/Editor/Tools/GameObjects/GameObjectComponentHelpers.cs, MCPForUnity/Editor/Helpers/GameObjectSerializer.cs, MCPForUnity/Editor/Tools/ManageAsset.cs, MCPForUnity/Editor/Tools/ManageScene.cs, MCPForUnity/Editor/Tools/Physics/PhysicsSettingsOps.cs, MCPForUnity/Editor/Tools/Physics/PhysicsSimulationOps.cs, MCPForUnity/Editor/Tools/Physics/PhysicsForceOps.cs
Physics tool entry points and shared editor helpers now return explicit errors or skip code when the relevant Physics or Physics2D module is unavailable. Rigidbody detection, simulation, force application, settings access, conflict checks, collider bounds enumeration, and physics-material creation are all wrapped in module guards.
Physics query, material, joint, and validation paths
MCPForUnity/Editor/Tools/Physics/PhysicsRigidbodyOps.cs, MCPForUnity/Editor/Tools/Physics/PhysicsQueryOps.cs, MCPForUnity/Editor/Tools/Physics/PhysicsMaterialOps.cs, MCPForUnity/Editor/Tools/Physics/CollisionMatrixOps.cs, MCPForUnity/Editor/Tools/Physics/JointOps.cs, MCPForUnity/Editor/Tools/Physics/PhysicsValidationOps.cs
Rigidbody lookup/configuration, physics queries, material creation/configuration/assignment, collision-matrix read/write, joint add/configure/remove/resolve, and validation checks now branch on compile-time Physics/Physics2D availability and return module-specific errors when needed.
Screen capture flow and documentation
MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs, MCPForUnity/Editor/Tools/ManageUI.cs, Server/src/services/tools/manage_camera.py, Server/src/services/tools/manage_physics.py, Server/src/services/tools/manage_ui.py, website/docs/reference/tools/core/manage_camera.md, website/docs/reference/tools/core/manage_physics.md, website/docs/reference/tools/ui/manage_ui.md
Screenshot capture and play-mode UI rendering now gate ScreenCapture usage behind MCP_HAS_SCREEN_CAPTURE, with camera fallbacks or explicit errors when absent. Tool descriptions and reference docs are updated to describe optional module requirements, fallback behavior, and dimension handling.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • CoplayDev/unity-mcp#1162: Also updates UnityPhysicsCompat.cs and ScreenshotUtility.cs to handle missing built-in Unity modules.
  • CoplayDev/unity-mcp#983: Introduces the physics tools and related ops that this change now gates on module availability.
  • CoplayDev/unity-mcp#1122: Adds the corresponding built-in Unity module dependencies that match these new compile-time defines.

Suggested reviewers: jordandunmire97-ai

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.45% 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
Title check ✅ Passed The title is concise and accurately captures the main change: making Physics/Screen Capture modules optional.
Description check ✅ Passed All required sections are present and mostly filled out, with clear change, testing, compatibility, and issue-link details.
Linked Issues check ✅ Passed The PR addresses #1172 by removing direct Physics type usage and gating module-dependent code so it compiles when Physics is disabled.
Out of Scope Changes check ✅ Passed I don't see substantive unrelated code changes; the docs and tool-description updates support the optional-module behavior.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6b1eb3bd69

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs Outdated

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs (1)

242-248: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clarify exception text for module-absent path.

When MCP_HAS_SCREEN_CAPTURE is undefined, this branch can throw "ScreenCapture.CaptureScreenshotAsTexture returned null...", which is misleading because ScreenCapture was never called. Please make the message include the module-missing case explicitly to improve operator diagnostics.

Proposed fix
-                    throw new InvalidOperationException("ScreenCapture.CaptureScreenshotAsTexture returned null and no fallback camera available.");
+                    throw new InvalidOperationException(
+                        "Cannot capture composited screenshot: Screen Capture module is unavailable (or capture returned null) and no fallback camera is available.");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs` around lines 242 - 248, The
exception message in the fallback block after FindAvailableCamera() is called is
misleading when MCP_HAS_SCREEN_CAPTURE is undefined, as it references
ScreenCapture.CaptureScreenshotAsTexture even though ScreenCapture was never
invoked in that code path. Update the InvalidOperationException message to
explicitly clarify that the error occurs when either the ScreenCapture module is
not installed or no fallback camera is available, improving clarity for operator
diagnostics. This will help distinguish between the cases where ScreenCapture
was actually called versus when the module was not present.
MCPForUnity/Editor/Tools/Physics/JointOps.cs (1)

71-95: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Handle explicit-dimension module absence before Rigidbody existence checks.

For explicit dimension requests, Line 73/Line 79 can return “has no Rigidbody/Rigidbody2D” even when that module is not installed. This should return the module-missing error first for accurate remediation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@MCPForUnity/Editor/Tools/Physics/JointOps.cs` around lines 71 - 95, When the
dimensionParam is explicitly set to "2d" or "3d", the code checks for Rigidbody
existence before verifying that the required physics module is installed. For
explicit dimension requests, add module availability checks before the existing
Rigidbody existence checks in both the dimensionParam == "2d" branch and the
dimensionParam == "3d" branch. If the required module is not installed, return a
module-missing error instead of a Rigidbody-missing error, so users get accurate
guidance on what to install first.
MCPForUnity/Editor/Tools/Physics/PhysicsForceOps.cs (1)

39-50: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Return module-missing errors before Rigidbody presence checks for explicit dimensions.

With dimension: "2d" or "3d", Line 47 and Line 50 can return “add Rigidbody” even when that physics module is compiled out, which is impossible for users to fix. Please gate explicit dimension requests with module-availability checks first, then run component validation.

💡 Suggested fix
-            if (dimensionParam == "2d")
-                is2D = true;
-            else if (dimensionParam == "3d")
-                is2D = false;
+            if (dimensionParam == "2d")
+            {
+#if !MCP_HAS_PHYSICS_2D
+                return new ErrorResponse("Physics 2D module (com.unity.modules.physics2d) is not installed.");
+#endif
+                is2D = true;
+            }
+            else if (dimensionParam == "3d")
+            {
+#if !MCP_HAS_PHYSICS
+                return new ErrorResponse("Physics module (com.unity.modules.physics) is not installed.");
+#endif
+                is2D = false;
+            }
             else
                 is2D = has2DRb && !has3DRb;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@MCPForUnity/Editor/Tools/Physics/PhysicsForceOps.cs` around lines 39 - 50,
The code validates Rigidbody presence after determining the dimension, but this
order causes misleading errors when explicit dimensions are requested for
unavailable physics modules. When dimensionParam is explicitly "2d" or "3d", add
module-availability checks before the Rigidbody validation logic at lines 47 and
50. Verify that the 2D physics module is compiled in when dimensionParam equals
"2d", and verify the 3D physics module is compiled in when dimensionParam equals
"3d", returning a module-unavailable error immediately if either check fails.
Only after confirming the required module exists should the code proceed to
validate that the appropriate Rigidbody component (has2DRb or has3DRb) is
present.
MCPForUnity/Editor/Tools/Physics/PhysicsRigidbodyOps.cs (1)

51-75: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Avoid generic “No Rigidbody” fallback before module-specific routing in GetRigidbody.

The check at Line 51 can short-circuit to a component-missing message even when the requested dimension’s module is unavailable. Let the dimension branch return module-specific errors first (or move this check after module/dimension resolution).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@MCPForUnity/Editor/Tools/Physics/PhysicsRigidbodyOps.cs` around lines 51 -
75, In the GetRigidbody method, the early check for missing rigidbodies (when
!has3D && !has2D) returns a generic error before the code determines which
physics dimension/module is needed. Relocate this check to occur after the is2D
logic is determined and after the conditional compilation checks for module
availability, so that module-specific errors (MCP_HAS_PHYSICS_2D and
MCP_HAS_PHYSICS) are returned first when appropriate, providing users with more
helpful error messages. Only return the generic "No Rigidbody" error if the
required module is actually available but the component is missing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@MCPForUnity/Editor/Tools/ManageAsset.cs`:
- Around line 13-21: Move the Unity version-specific conditional compilation
logic from ManageAsset.cs into a compatibility shim file. Specifically, the `#if`
UNITY_6000_0_OR_NEWER preprocessor directives that define PhysicsMaterialType
and PhysicsMaterialCombine type aliases should be moved to
MCPForUnity/Runtime/Helpers/UnityPhysicsCompat.cs (or similar shim file). In
that shim file, define these type aliases with the appropriate conditional
branches for different Unity versions. Then in ManageAsset.cs, replace the
entire conditional block (lines 13-21) with a single using statement that
imports these type aliases from the compat shim, eliminating all
version-specific branching from the call site.

---

Outside diff comments:
In `@MCPForUnity/Editor/Tools/Physics/JointOps.cs`:
- Around line 71-95: When the dimensionParam is explicitly set to "2d" or "3d",
the code checks for Rigidbody existence before verifying that the required
physics module is installed. For explicit dimension requests, add module
availability checks before the existing Rigidbody existence checks in both the
dimensionParam == "2d" branch and the dimensionParam == "3d" branch. If the
required module is not installed, return a module-missing error instead of a
Rigidbody-missing error, so users get accurate guidance on what to install
first.

In `@MCPForUnity/Editor/Tools/Physics/PhysicsForceOps.cs`:
- Around line 39-50: The code validates Rigidbody presence after determining the
dimension, but this order causes misleading errors when explicit dimensions are
requested for unavailable physics modules. When dimensionParam is explicitly
"2d" or "3d", add module-availability checks before the Rigidbody validation
logic at lines 47 and 50. Verify that the 2D physics module is compiled in when
dimensionParam equals "2d", and verify the 3D physics module is compiled in when
dimensionParam equals "3d", returning a module-unavailable error immediately if
either check fails. Only after confirming the required module exists should the
code proceed to validate that the appropriate Rigidbody component (has2DRb or
has3DRb) is present.

In `@MCPForUnity/Editor/Tools/Physics/PhysicsRigidbodyOps.cs`:
- Around line 51-75: In the GetRigidbody method, the early check for missing
rigidbodies (when !has3D && !has2D) returns a generic error before the code
determines which physics dimension/module is needed. Relocate this check to
occur after the is2D logic is determined and after the conditional compilation
checks for module availability, so that module-specific errors
(MCP_HAS_PHYSICS_2D and MCP_HAS_PHYSICS) are returned first when appropriate,
providing users with more helpful error messages. Only return the generic "No
Rigidbody" error if the required module is actually available but the component
is missing.

In `@MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs`:
- Around line 242-248: The exception message in the fallback block after
FindAvailableCamera() is called is misleading when MCP_HAS_SCREEN_CAPTURE is
undefined, as it references ScreenCapture.CaptureScreenshotAsTexture even though
ScreenCapture was never invoked in that code path. Update the
InvalidOperationException message to explicitly clarify that the error occurs
when either the ScreenCapture module is not installed or no fallback camera is
available, improving clarity for operator diagnostics. This will help
distinguish between the cases where ScreenCapture was actually called versus
when the module was not present.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4612f8a0-640e-44af-9530-b3cc40072327

📥 Commits

Reviewing files that changed from the base of the PR and between dccecd6 and 6b1eb3b.

📒 Files selected for processing (20)
  • MCPForUnity/Editor/Helpers/ComponentOps.cs
  • MCPForUnity/Editor/Helpers/GameObjectSerializer.cs
  • MCPForUnity/Editor/MCPForUnity.Editor.asmdef
  • MCPForUnity/Editor/Tools/GameObjects/GameObjectComponentHelpers.cs
  • MCPForUnity/Editor/Tools/ManageAsset.cs
  • MCPForUnity/Editor/Tools/ManageScene.cs
  • MCPForUnity/Editor/Tools/Physics/CollisionMatrixOps.cs
  • MCPForUnity/Editor/Tools/Physics/JointOps.cs
  • MCPForUnity/Editor/Tools/Physics/ManagePhysics.cs
  • MCPForUnity/Editor/Tools/Physics/PhysicsForceOps.cs
  • MCPForUnity/Editor/Tools/Physics/PhysicsMaterialOps.cs
  • MCPForUnity/Editor/Tools/Physics/PhysicsQueryOps.cs
  • MCPForUnity/Editor/Tools/Physics/PhysicsRigidbodyOps.cs
  • MCPForUnity/Editor/Tools/Physics/PhysicsSettingsOps.cs
  • MCPForUnity/Editor/Tools/Physics/PhysicsSimulationOps.cs
  • MCPForUnity/Editor/Tools/Physics/PhysicsValidationOps.cs
  • MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs
  • MCPForUnity/Runtime/Helpers/UnityPhysicsCompat.cs
  • MCPForUnity/Runtime/MCPForUnity.Runtime.asmdef
  • MCPForUnity/package.json
💤 Files with no reviewable changes (1)
  • MCPForUnity/package.json

Comment on lines +13 to +21
#if MCP_HAS_PHYSICS
#if UNITY_6000_0_OR_NEWER
using PhysicsMaterialType = UnityEngine.PhysicsMaterial;
using PhysicsMaterialCombine = UnityEngine.PhysicsMaterialCombine;
#else
using PhysicsMaterialType = UnityEngine.PhysicMaterial;
using PhysicsMaterialCombine = UnityEngine.PhysicMaterialCombine;
#endif
#endif

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.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Move Unity version branching into a compat shim.

This #if UNITY_6000_0_OR_NEWER gate is in a tool call site. Please move the API-version split into MCPForUnity/Runtime/Helpers/Unity*Compat.cs and consume a single shim type/API from ManageAsset.

As per coding guidelines, "MCPForUnity/**/*.cs: Unity API version compatibility issues must use shims in MCPForUnity/Runtime/Helpers/Unity*Compat.cs rather than sprinkling #if UNITY_x_y_OR_NEWER at call sites."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@MCPForUnity/Editor/Tools/ManageAsset.cs` around lines 13 - 21, Move the Unity
version-specific conditional compilation logic from ManageAsset.cs into a
compatibility shim file. Specifically, the `#if` UNITY_6000_0_OR_NEWER
preprocessor directives that define PhysicsMaterialType and
PhysicsMaterialCombine type aliases should be moved to
MCPForUnity/Runtime/Helpers/UnityPhysicsCompat.cs (or similar shim file). In
that shim file, define these type aliases with the appropriate conditional
branches for different Unity versions. Then in ManageAsset.cs, replace the
entire conditional block (lines 13-21) with a single using statement that
imports these type aliases from the compat shim, eliminating all
version-specific branching from the call site.

Source: Coding guidelines

@LuuOW LuuOW left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Technical audit: code patterns and architectural layout verified for system reliability.

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
MCPForUnity/Editor/Tools/ManageUI.cs (1)

944-950: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Reset pending-capture state when Begin fails synchronously.

At Line 944-Line 950, s_pendingCaptureStarted is set before ScreenshotCapturer.Begin(...). If Begin throws before callback registration/completion, the flag stays true and all later calls are blocked as “capture_in_progress”.

Suggested fix
                 s_pendingCaptureDone = false;
                 s_pendingCaptureTex = null;
                 s_pendingCaptureStarted = true;
-                ScreenshotCapturer.Begin(1, tex =>
-                {
-                    s_pendingCaptureTex = tex;
-                    s_pendingCaptureDone = true;
-                    s_pendingCaptureStarted = false;
-                });
+                try
+                {
+                    ScreenshotCapturer.Begin(1, tex =>
+                    {
+                        s_pendingCaptureTex = tex;
+                        s_pendingCaptureDone = true;
+                        s_pendingCaptureStarted = false;
+                    });
+                }
+                catch
+                {
+                    s_pendingCaptureStarted = false;
+                    throw;
+                }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@MCPForUnity/Editor/Tools/ManageUI.cs` around lines 944 - 950, The flag
s_pendingCaptureStarted is set to true before calling
ScreenshotCapturer.Begin(), but if Begin() throws a synchronous exception, the
flag remains true and blocks all subsequent capture attempts. Wrap the
ScreenshotCapturer.Begin() call in a try-catch block to reset
s_pendingCaptureStarted back to false in the catch handler, ensuring the pending
capture state is properly cleaned up if an exception occurs during the Begin
call.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@MCPForUnity/Editor/Tools/ManageUI.cs`:
- Around line 944-950: The flag s_pendingCaptureStarted is set to true before
calling ScreenshotCapturer.Begin(), but if Begin() throws a synchronous
exception, the flag remains true and blocks all subsequent capture attempts.
Wrap the ScreenshotCapturer.Begin() call in a try-catch block to reset
s_pendingCaptureStarted back to false in the catch handler, ensuring the pending
capture state is properly cleaned up if an exception occurs during the Begin
call.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d80c1f43-9ec7-41bd-b63b-0480ecbd06a0

📥 Commits

Reviewing files that changed from the base of the PR and between 6b1eb3b and 0878bba.

📒 Files selected for processing (2)
  • MCPForUnity/Editor/Tools/ManageUI.cs
  • MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs

@ArkTarusov

Copy link
Copy Markdown
Author

Addressed the review + documented the optional-module behavior.

Screen Capture fix (0878bba): play-mode render_ui and the ScreenshotCapturer MonoBehaviour are now fully gated behind MCP_HAS_SCREEN_CAPTURE. Without the module, ScreenshotCapturer is compiled out and play-mode render_ui returns a clear error (capture in editor mode instead) rather than queuing a capture that never completes. Verified by recompiling with the module stripped (0 errors).

Docs (d30bbc4): tool descriptions now state the requirements — manage_physics needs the Physics / Physics 2D modules (dimension defaults to 3d, so pass 2d explicitly without the 3D module); render_ui (play mode) and manage_camera screenshot note the Screen Capture module and their fallbacks.

Both modules stay optional — the package compiles/runs with any subset and degrades gracefully.

@jordandunmire97-ai jordandunmire97-ai left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please understand I am reading it and the very much beautiful alternatives . Please understand I know it needs to be reviewed i am just approving for myself as I can barely type this .

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.

[Bug]: Compile error when Physics module is disabled (regression in 9.7.1)

3 participants