Skip to content

fix: declare required Unity module dependencies#1122

Merged
Scriptwonder merged 2 commits into
CoplayDev:betafrom
sean2077:codex/add-imageconversion-dependency
May 26, 2026
Merged

fix: declare required Unity module dependencies#1122
Scriptwonder merged 2 commits into
CoplayDev:betafrom
sean2077:codex/add-imageconversion-dependency

Conversation

@sean2077
Copy link
Copy Markdown

@sean2077 sean2077 commented May 13, 2026

Summary

Adds missing built-in Unity module dependencies to the MCP for Unity package manifest:

  • com.unity.modules.imageconversion
  • com.unity.modules.physics2d
  • com.unity.modules.screencapture

Root Cause

MCPForUnity.Runtime directly uses APIs from these modules:

  • Texture2D.EncodeToPNG() from Image Conversion
  • Physics2D from Physics 2D
  • ScreenCapture from Screen Capture

Projects that do not already enable these built-in modules can fail script compilation after installing the package.

Validation

Validated in a Unity 6000.3.15f1 project that originally failed compiling MCPForUnity.Runtime with missing module references. After declaring the dependencies, Unity Package Manager resolved the three built-in modules and batchmode script compilation completed successfully.

Summary by CodeRabbit

  • Chores
    • Extended project dependencies to include additional Unity modules: animation, image conversion, physics (3D), 2D physics, UI Elements, screen capture, and web request handling.

Review Change Stack

MCPForUnity.Runtime uses Texture2D.EncodeToPNG, Physics2D, and ScreenCapture APIs. Declaring their built-in modules prevents Unity projects that do not already enable those modules from failing script compilation.

Co-authored-by: Codex <noreply@openai.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 77cdc69f-6791-4d3f-a51f-d3e3f1053c64

📥 Commits

Reviewing files that changed from the base of the PR and between f96c39b and ec9b22a.

📒 Files selected for processing (1)
  • MCPForUnity/package.json

📝 Walkthrough

Walkthrough

Seven Unity module dependencies—com.unity.modules.animation, com.unity.modules.imageconversion, com.unity.modules.physics, com.unity.modules.physics2d, com.unity.modules.uielements, com.unity.modules.screencapture, and com.unity.modules.unitywebrequest—are added to MCPForUnity/package.json, each pinned to 1.0.0.

Changes

Unity Module Dependencies

Layer / File(s) Summary
Unity module dependencies
MCPForUnity/package.json
Added seven new Unity module dependencies—com.unity.modules.animation, com.unity.modules.imageconversion, com.unity.modules.physics, com.unity.modules.physics2d, com.unity.modules.uielements, com.unity.modules.screencapture, and com.unity.modules.unitywebrequest—each set to 1.0.0 in the package manifest.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit nudges package.json with care,
Seven tiny modules tucked in there—
Animation, physics, screens that gleam,
Requests and images join the team. 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: declare required Unity module dependencies' accurately and concisely summarizes the main change—adding missing Unity module dependencies to the package manifest.
Description check ✅ Passed The PR description includes a summary of changes, root cause analysis, and validation testing, but lacks several required template sections like Type of Change checkbox, detailed Testing/Screenshots section, and Documentation Updates confirmation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

@Scriptwonder Scriptwonder marked this pull request as ready for review May 26, 2026 07:24
Copilot AI review requested due to automatic review settings May 26, 2026 07:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Unity package manifest to explicitly declare built-in Unity module dependencies that the package’s code relies on, preventing script compilation failures in projects where those modules are disabled.

Changes:

  • Added com.unity.modules.imageconversion dependency to ensure Texture2D.EncodeToPNG() APIs are available.
  • Added com.unity.modules.physics2d dependency to ensure Physics2D APIs are available.
  • Added com.unity.modules.screencapture dependency to ensure ScreenCapture APIs are available.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread MCPForUnity/package.json
Comment on lines +10 to 14
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.nuget.newtonsoft-json": "3.0.2",
"com.unity.test-framework": "1.1.31"
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/package.json`:
- Around line 10-12: Add the missing 3D physics Unity module by adding the
package "com.unity.modules.physics" with the same version string used for other
modules (e.g., "1.0.0") to MCPForUnity/package.json so the runtime can resolve
UnityEngine.Physics used in MCPForUnity/Runtime/Helpers/UnityPhysicsCompat.cs
(see typeof(Physics).GetProperty(...)); ensure the physics and physics2d entries
use the same version format as the other modules to match the test project
manifests.
🪄 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: 35f384c4-cef2-4c88-9d97-aa1127072290

📥 Commits

Reviewing files that changed from the base of the PR and between a2a5edf and f96c39b.

📒 Files selected for processing (1)
  • MCPForUnity/package.json

Comment thread MCPForUnity/package.json
@Scriptwonder Scriptwonder merged commit e3f822b into CoplayDev:beta May 26, 2026
1 check passed
Scriptwonder added a commit that referenced this pull request May 26, 2026
…arations (#1122)

Since #1122 declared the Physics 2D, Screen Capture, Image Conversion, etc.
built-in modules as required deps in package.json, Unity Package Manager now
keeps them enabled while MCP for Unity is installed. Two defensive layers
that protected against the now-impossible "module disabled" case become dead
code, plus one sub-floor preprocessor gate that was always-true on our
declared `unity: 2021.3` floor.

Tier 1A — UnityPhysicsCompat.cs
- Revert `Type.GetType("UnityEngine.Physics2D, UnityEngine.Physics2DModule")`
  to `typeof(Physics2D)`. The property-level reflection (for `autoSyncTransforms`
  deprecation in Unity 6.x) stays — that's a different concern.

Tier 1B — TrailControl.cs
- Strip `#if UNITY_2021_1_OR_NEWER` gate. Package floor is 2021.3 per
  package.json, so the `#else` branch ("AddPosition requires Unity 2021.1+")
  is unreachable.

Tier 2 — ScreenshotUtility.cs + callers
- Remove `IsScreenCaptureModuleAvailable` property, `ScreenCaptureModuleNotAvailableError`
  constant, `InvokeCaptureScreenshotAsTexture` helper, and the
  `s_captureScreenshotMethod` / `s_captureScreenshotAsTextureMethod` /
  `s_screenCaptureModuleAvailable` reflection caches.
- Replace reflective `MethodInfo.Invoke` calls with direct `ScreenCapture.X`
  calls in `CaptureToProjectFolder`, `CaptureComposited`, and the
  `ScreenshotCapturer` MonoBehaviour.
- Camera-based fallback path (`FindAvailableCamera` + `CaptureFromCameraToProjectFolder`)
  is preserved — it still handles transient null returns from `ScreenCapture`
  inside `CaptureComposited`.
- Drop pre-flight `if (!IsScreenCaptureModuleAvailable)` gates in
  `ManageUI.cs` (UI render) and `ManageScene.cs` (screenshot path).
- `ProjectInfo` resource: `screenCapture` field is now an invariant `true`
  (preserves API shape for `mcpforunity://project/info` consumers).

Net: 144 lines removed, 15 added. No new tests — the changes are pure
removal of code paths that cannot fire with the current deps declared.

Related: #1160, #1122.
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.

3 participants