Skip to content

Conversation

@SabadashDenis
Copy link

@SabadashDenis SabadashDenis commented Jan 18, 2026

Problem

When WebGL is the active build target, the project fails to compile:
error CS0103: The name 'ScreenCapture' does not exist in the current context

Solution

Move ScreenshotUtility.cs from Runtime/Helpers/ to Editor/Helpers/.

Why this works

ScreenCapture doesn't exist in WebGL scripting backend. Editor scripts compile with desktop backend regardless of target platform. No functionality impact since MCP tools only run in Editor.

Fixes #574

Summary by Sourcery

Move screenshot capture utilities into the editor-only helpers namespace to avoid WebGL build errors.

Bug Fixes:

  • Resolve WebGL compilation failure caused by referencing ScreenCapture from runtime code.

Enhancements:

  • Restrict ScreenshotUtility to editor-only helpers to align with its actual usage in MCP editor tools.

Summary by CodeRabbit

  • Refactor
    • Reorganized internal screenshot utility components to improve code structure and organization.

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

ScreenCapture doesn't exist in WebGL scripting backend, causing CS0103 error when WebGL is the active build target. Editor scripts compile with desktop backend regardless of target platform. No functionality
   impact since MCP tools only run in Editor.
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 18, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Moves ScreenshotUtility into an Editor-only context to avoid WebGL compilation errors by changing its namespace and references, and removes the now-unneeded runtime helpers folder metadata.

Class diagram for ScreenshotUtility editor migration

classDiagram
namespace MCPForUnity_Runtime_Helpers {
  class ScreenshotUtility
  class ScreenshotCaptureResult
}

namespace MCPForUnity_Editor_Helpers {
  class ScreenshotUtility
  class ScreenshotCaptureResult
}

namespace MCPForUnity_Editor_Tools {
  class ManageScene
}

ManageScene ..> ScreenshotUtility : uses

MCPForUnity_Runtime_Helpers_ScreenshotUtility <|.. MCPForUnity_Editor_Helpers_ScreenshotUtility
Loading

File-Level Changes

Change Details Files
Restrict ScreenshotUtility to editor-only usage to avoid WebGL build target compilation failures.
  • Relocated ScreenshotUtility from the runtime helpers folder to the editor helpers folder so it compiles with the editor backend only
  • Updated ScreenshotUtility namespace from MCPForUnity.Runtime.Helpers to MCPForUnity.Editor.Helpers to match its new location
  • Removed the runtime helper reference for ScreenshotUtility from ManageScene since it now resides in the editor helpers namespace
  • Deleted the obsolete Runtime/Helpers folder metadata file, as ScreenshotUtility is no longer part of runtime code
MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs
MCPForUnity/Editor/Helpers/ScreenshotUtility.cs
MCPForUnity/Editor/Tools/ManageScene.cs
MCPForUnity/Runtime/Helpers.meta

Assessment against linked issues

Issue Objective Addressed Explanation
#574 Restrict ScreenshotUtility.cs to the editor-only assembly by moving it from Runtime/Helpers to Editor/Helpers and updating its namespace to MCPForUnity.Editor.Helpers.
#574 Update ManageScene.cs to reference ScreenshotUtility from the MCPForUnity.Editor.Helpers namespace instead of MCPForUnity.Runtime.Helpers.
#574 Remove obsolete conditional compilation guards around the ScreenCapture call in ScreenshotUtility.cs, as they are no longer needed when the file is editor-only. The diff only shows a namespace change for ScreenshotUtility.cs and path relocation; it does not show any modifications removing #if guards around ScreenCapture. There is no evidence in the provided changes that these conditional compilation directives were removed.

Possibly linked issues


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
Copy link
Contributor

coderabbitai bot commented Jan 18, 2026

📝 Walkthrough

Walkthrough

ScreenshotUtility is relocated from the Runtime namespace to the Editor namespace to resolve WebGL compilation errors. This involves updating the namespace declaration in ScreenshotUtility.cs, removing the obsolete Runtime import from ManageScene.cs, and deleting the associated Runtime metadata file.

Changes

Cohort / File(s) Summary
ScreenshotUtility relocation
MCPForUnity/Editor/Helpers/ScreenshotUtility.cs, MCPForUnity/Editor/Tools/ManageScene.cs
Updated namespace from MCPForUnity.Runtime.Helpers to MCPForUnity.Editor.Helpers for ScreenshotUtility. Removed corresponding using directive in ManageScene.cs.
Runtime Helpers cleanup
MCPForUnity/Runtime/Helpers.meta
Deleted Unity metadata file for Runtime Helpers folder, reflecting removal of ScreenshotUtility from Runtime assembly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A screenshot hops from Runtime's den,
To Editor's warm embrace instead,
No WebGL woes to plague us then,
Just namespace moves and imports shed,
Our utility finds home again! 📸

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The PR implements key changes from issue #574: moving ScreenshotUtility.cs to Editor/Helpers, updating its namespace to MCPForUnity.Editor.Helpers, and updating the import in ManageScene.cs. However, the summary does not explicitly confirm that platform guards were removed from ScreenCapture calls. Verify that #if guards around ScreenCapture usage have been removed as required by issue #574 objective #4, since the raw summary only documents namespace/file relocation.
✅ 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 clearly describes the main change: fixing WebGL compilation issues with ScreenshotUtility.cs. It is concise, specific, and directly related to the primary objective of the changeset.
Out of Scope Changes check ✅ Passed All documented changes align with the objectives from issue #574: namespace relocation, file movement, import updates, and metadata cleanup. No extraneous modifications were detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The comment above ScreenshotCaptureResult still refers to avoiding editor-only dependencies in runtime code, which no longer matches the class’s location/role and should be updated or removed for clarity.
  • In ManageScene.cs, the inline comment // For ScreenshotUtility was removed along with the using, but the remaining // For Response class comment could be clarified or generalized now that this file imports multiple helpers from the same namespace.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The comment above `ScreenshotCaptureResult` still refers to avoiding editor-only dependencies in runtime code, which no longer matches the class’s location/role and should be updated or removed for clarity.
- In `ManageScene.cs`, the inline comment `// For ScreenshotUtility` was removed along with the using, but the remaining `// For Response class` comment could be clarified or generalized now that this file imports multiple helpers from the same namespace.

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.

Copy link
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

Caution

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

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

97-115: Texture2D is never destroyed — memory leak.

The Texture2D allocated at line 103 is not disposed after encoding to PNG. Since this is Editor code, use DestroyImmediate to release the texture memory.

🐛 Proposed fix
             try
             {
                 camera.targetTexture = rt;
                 camera.Render();

                 RenderTexture.active = rt;
                 var tex = new Texture2D(width, height, TextureFormat.RGBA32, false);
-                tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
-                tex.Apply();
-
-                byte[] png = tex.EncodeToPNG();
-                File.WriteAllBytes(normalizedFullPath, png);
+                try
+                {
+                    tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
+                    tex.Apply();
+
+                    byte[] png = tex.EncodeToPNG();
+                    File.WriteAllBytes(normalizedFullPath, png);
+                }
+                finally
+                {
+                    UnityEngine.Object.DestroyImmediate(tex);
+                }
             }
             finally
             {
🤖 Fix all issues with AI agents
In `@MCPForUnity/Editor/Helpers/ScreenshotUtility.cs`:
- Around line 6-7: The inline comment following the namespace
MCPForUnity.Editor.Helpers is stale—remove or rewrite it to reflect that this
file (ScreenshotUtility) now lives in the Editor assembly and is Editor-only;
update the comment text to mention "Editor-only utilities" or delete the comment
entirely so it no longer references "Runtime Utilities" or "runtime code", and
ensure the change is applied in the ScreenshotUtility.cs header near the
namespace declaration.

Comment on lines +6 to 7
namespace MCPForUnity.Editor.Helpers
//The reason for having another Runtime Utilities in additional to Editor Utilities is to avoid Editor-only dependencies in this runtime code.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Stale comment references Runtime context.

The namespace update on line 6 is correct. However, line 7's comment still refers to "Runtime Utilities" and "runtime code," which is now misleading since this file has been relocated to the Editor assembly.

📝 Suggested fix
 namespace MCPForUnity.Editor.Helpers
-//The reason for having another Runtime Utilities in additional to Editor Utilities is to avoid Editor-only dependencies in this runtime code.
 {

Or update the comment to reflect the new Editor-only purpose if documentation is still desired.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
namespace MCPForUnity.Editor.Helpers
//The reason for having another Runtime Utilities in additional to Editor Utilities is to avoid Editor-only dependencies in this runtime code.
namespace MCPForUnity.Editor.Helpers
{
🤖 Prompt for AI Agents
In `@MCPForUnity/Editor/Helpers/ScreenshotUtility.cs` around lines 6 - 7, The
inline comment following the namespace MCPForUnity.Editor.Helpers is
stale—remove or rewrite it to reflect that this file (ScreenshotUtility) now
lives in the Editor assembly and is Editor-only; update the comment text to
mention "Editor-only utilities" or delete the comment entirely so it no longer
references "Runtime Utilities" or "runtime code", and ensure the change is
applied in the ScreenshotUtility.cs header near the namespace declaration.

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.

ScreenshotUtility.cs fails to compile when target platform is WebGL

1 participant