Skip to content

Feat/optional physics screencapture modules#1208

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

Feat/optional physics screencapture modules#1208
ArkTarusov wants to merge 2 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
    • Improved module support with conditional compilation for physics (3D/2D) and screen capture features. The tool now gracefully handles projects missing specific Unity modules, providing clear error messages instead of failures. Added runtime type resolution for enhanced compatibility across different Unity project configurations.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds versionDefines entries to both .asmdef files to define MCP_HAS_PHYSICS, MCP_HAS_PHYSICS_2D, and MCP_HAS_SCREEN_CAPTURE compile-time symbols when the corresponding Unity modules are present. All physics and screen capture code across editor tools and runtime helpers is then wrapped in matching #if guards, returning ErrorResponse when a module is absent. UnityPhysicsCompat switches from compile-time typeof references to runtime Type.GetType resolution.

Changes

Optional Unity Module Compile Guards

Layer / File(s) Summary
Assembly definitions: versionDefines for physics and screen capture
MCPForUnity/Editor/MCPForUnity.Editor.asmdef, MCPForUnity/Runtime/MCPForUnity.Runtime.asmdef, MCPForUnity/package.json
Both Editor and Runtime asmdef files gain versionDefines mapping com.unity.modules.physics, com.unity.modules.physics2d, and com.unity.modules.screencapture to MCP_HAS_PHYSICS, MCP_HAS_PHYSICS_2D, and MCP_HAS_SCREEN_CAPTURE. package.json has a minor dependency reorder.
UnityPhysicsCompat: runtime type resolution
MCPForUnity/Runtime/Helpers/UnityPhysicsCompat.cs
Removes using UnityEngine; and adds cached PhysicsType/Physics2DType fields resolved via Type.GetType at runtime; updates all reflection property probes (autoSyncTransforms, simulationMode, autoSimulation) from typeof(Physics)/typeof(Physics2D) to the nullable cached types.
Top-level command guard and shared editor helpers
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
ManagePhysics.HandleCommand gains a #if !(MCP_HAS_PHYSICS || MCP_HAS_PHYSICS_2D) early-return ErrorResponse. Physics conflict checks, Collider.GeometryHolder exclusion, PhysicsMaterial type aliases and creation path, and TryGetColliderBounds collider enumeration are all wrapped with matching #if guards.
Physics settings, simulation, and force ops
MCPForUnity/Editor/Tools/Physics/PhysicsSettingsOps.cs, MCPForUnity/Editor/Tools/Physics/PhysicsSimulationOps.cs, MCPForUnity/Editor/Tools/Physics/PhysicsForceOps.cs
PhysicsSettingsOps.Ping builds a conditional dictionary; GetSettings/SetSettings3D/SetSettings2D return ErrorResponse when the module symbol is absent. PhysicsSimulationOps gates 2D/3D simulation and Rigidbody collection. PhysicsForceOps guards ApplyNormalForce 2D/3D paths and ApplyExplosionForce.
PhysicsRigidbodyOps conditional compilation
MCPForUnity/Editor/Tools/Physics/PhysicsRigidbodyOps.cs
GetRigidbody and ConfigureRigidbody guard has3D/has2D detection and dimension routing; GetRigidbody3D/2D and ConfigureRigidbody3D/2D helper implementations are enclosed in matching #if blocks.
PhysicsQueryOps conditional compilation
MCPForUnity/Editor/Tools/Physics/PhysicsQueryOps.cs
All five public entry points (Raycast, Overlap, Shapecast, RaycastAll, Linecast) have 2D/3D dispatch wrapped in #if MCP_HAS_PHYSICS_2D/#if MCP_HAS_PHYSICS with ErrorResponse fallbacks; helper implementations and FormatOverlapResults helpers are enclosed in matching blocks.
PhysicsMaterialOps, CollisionMatrixOps, JointOps, PhysicsValidationOps
MCPForUnity/Editor/Tools/Physics/PhysicsMaterialOps.cs, MCPForUnity/Editor/Tools/Physics/CollisionMatrixOps.cs, MCPForUnity/Editor/Tools/Physics/JointOps.cs, MCPForUnity/Editor/Tools/Physics/PhysicsValidationOps.cs
PhysicsMaterialOps gates Create/Configure/Assign routing and all helpers. CollisionMatrixOps wraps Get/SetCollisionMatrix dimension branches. JointOps wraps type maps, AddJoint wiring, ConfigureJoint motor/limits/spring/drive sections, and RemoveJoint/ResolveJoint auto-detection. PhysicsValidationOps guards all per-object and scene-level validation checks.
ScreenshotUtility MCP_HAS_SCREEN_CAPTURE guards
MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs
CaptureToProjectFolder, CaptureComposited, CaptureCompositedAfterFrame, and ScreenshotCapturer.Start are each wrapped with #if MCP_HAS_SCREEN_CAPTURE; camera-based fallbacks are used when the screen capture module is absent.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • CoplayDev/unity-mcp#1162: Modifies the same UnityPhysicsCompat.cs and ScreenshotUtility.cs runtime helpers to handle disabled Unity built-in modules via module-availability gating and reflection.
  • CoplayDev/unity-mcp#1168: Directly adjusts UnityPhysicsCompat.cs Physics2D property resolution logic in the same compat layer this PR extends to full runtime type resolution.
  • CoplayDev/unity-mcp#1132: Introduces CaptureCompositedAfterFrame/ScreenshotCapturer in ScreenshotUtility.cs, which this PR now gates behind MCP_HAS_SCREEN_CAPTURE.

Suggested labels

safe-to-test, full-matrix

Poem

🐇 Hop, hop, the modules may sleep,
#if guards now stand watch, running deep.
No physics? No crash! Just a kind error note,
Type.GetType finds what the compiler forgot.
ScreenCapture absent? The camera steps in—
Every module optional, yet nothing falls thin! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.70% 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 'Feat/optional physics screencapture modules' accurately summarizes the main change of making Physics, Physics 2D, and Screen Capture modules optional through versionDefines.
Description check ✅ Passed The PR description comprehensively covers all required template sections: description, type of change, changes made, compatibility/testing, and related issues; all critical information is present and complete.
Linked Issues check ✅ Passed The PR fully addresses issue #1172 by making Physics modules optional via versionDefines and updating UnityPhysicsCompat.cs to use runtime type resolution instead of compile-time typeof, enabling compilation when modules are disabled.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving issue #1172: adding versionDefines, conditionally compiling physics/screencapture code, removing forced module dependencies, and updating type resolution; no unrelated changes detected.

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

✨ 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 and usage tips.

@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 on lines +778 to +781
#if MCP_HAS_SCREEN_CAPTURE
try { tex = ScreenCapture.CaptureScreenshotAsTexture(_superSize); }
catch (Exception ex) { Debug.LogError($"[MCP for Unity] CaptureScreenshotAsTexture failed: {ex.Message}"); }
#endif

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle missing Screen Capture before queuing UI captures

When the Screen Capture module is disabled, this coroutine compiles out the only assignment to tex and still invokes the callback with null. The play-mode render_ui path in ManageUI queues ScreenshotCapturer.Begin and only treats the capture as ready when s_pendingCaptureTex != null, so in projects without com.unity.modules.screencapture each follow-up call skips the ready branch and queues another pending capture forever instead of falling back or returning an error.

Useful? React with 👍 / 👎.

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

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)

2 participants