-
Notifications
You must be signed in to change notification settings - Fork 628
Description
Environment:
- Unity 2022.3.x (or newer)
- WebGL target platform
Error:
Assets\Plugins\UnityMCP\Runtime\Helpers\ScreenshotUtility.cs(54,13):
error CS0103: The name 'ScreenCapture' does not exist in the current context
Root Cause:
On WebGL platform, Unity completely strips the ScreenCapture class from UnityEngine assembly. The class doesn't exist at compile time, so preprocessor directives like #if !UNITY_WEBGL or #if UNITY_EDITOR
cannot help — the compiler fails before evaluating runtime conditions.
Current location Runtime/Helpers/ causes the file to be compiled for all platforms including WebGL.
Analysis:
ScreenshotUtility is only called from ManageScene.cs located in Editor/Tools/. MCP functionality is Editor-only, so this utility has no runtime use case.
The comment in the file states:
"The reason for having another Runtime Utilities in additional to Editor Utilities is to avoid Editor-only dependencies in this runtime code."
This intent doesn't apply here since ScreenCapture.CaptureScreenshot() is unavailable in WebGL runtime anyway.
Solution:
Move ScreenshotUtility.cs from Runtime/Helpers/ to Editor/Helpers/.
The Editor assembly (MCPForUnity.Editor.asmdef) has "includePlatforms": ["Editor"], which excludes it from platform-specific compilation entirely. ScreenCapture is always available in Editor context.
Required changes:
- Move Runtime/Helpers/ScreenshotUtility.cs → Editor/Helpers/ScreenshotUtility.cs
- Update namespace: MCPForUnity.Runtime.Helpers → MCPForUnity.Editor.Helpers
- Update import in ManageScene.cs: using MCPForUnity.Editor.Helpers;
- Remove obsolete #if guards around ScreenCapture call (now unnecessary)