You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ScreenshotUtility.cs fails to compile when target platform is WebGL #574
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.
There is already an asmdef for the Runtime folder (MCPForUnity.Runtime.asmdef). I tried adding "excludePlatforms": ["WebGL"] to it, but this doesn't solve the compilation error.
ExcludePlatforms controls whether the compiled assembly is included in the final build, but Unity still compiles the C# code for the active build target. So when a developer has WebGL selected as their active platform in Build Settings, Unity compiles Runtime scripts using the WebGL scripting backend, where ScreenCapture class doesn't exist. This results in CS0103 error even though the assembly would be excluded from the actual build.
Using #if !UNITY_WEBGL preprocessor guards also won't work properly — it would fix the compilation error, but screenshots wouldn't work in the Editor when WebGL is the active platform, since UNITY_WEBGL is defined based on the build target, not the runtime environment.
Moving ScreenshotUtility.cs to the Editor/ folder solves both problems because Editor scripts are always compiled using the desktop scripting backend, regardless of the active build target. Since MCP tools only run in the Editor anyway, this doesn't change any functionality.
I see your point.
The naming might be confusing: runtime actually means PlayMode, as many Editor folder tools rely on APIs that can only run on editor time. I think moving to Editor is fine, but I was thinking of expanding the runtime to include a lot more runtime-runable tools in the future. Will make that change if I cannot find a better solution these two weeks.
Is this also related and/or will it fix this bug? Sounds like it's the same you had just with another platform.
I've opened a project with unity 6000.3.5f2 (LTS) on the Android Platform and got this:
Library\PackageCache\com.coplaydev.unity-mcp@9c2049bb148f\Runtime\Helpers\ScreenshotUtility.cs(54,13): error CS0103: The name 'ScreenCapture' does not exist in the current context
I had to manually enable the ScreenCapture Component in the PackageManager and then the error disappeared:
Is this also related and/or will it fix this bug? Sounds like it's the same you had just with another platform.
I've opened a project with unity 6000.3.5f2 (LTS) on the Android Platform and got this:
Library\PackageCache\com.coplaydev.unity-mcp@9c2049bb148f\Runtime\Helpers\ScreenshotUtility.cs(54,13): error CS0103: The name 'ScreenCapture' does not exist in the current context
I had to manually enable the ScreenCapture Component in the PackageManager and then the error disappeared:
Oh I see. @SabadashDenis Can you check if WebGL enable this feature by default? This might be the actual issue.
Is this also related and/or will it fix this bug? Sounds like it's the same you had just with another platform.
I've opened a project with unity 6000.3.5f2 (LTS) on the Android Platform and got this: Library\PackageCache\com.coplaydev.unity-mcp@9c2049bb148f\Runtime\Helpers\ScreenshotUtility.cs(54,13): error CS0103: The name 'ScreenCapture' does not exist in the current context
I had to manually enable the ScreenCapture Component in the PackageManager and then the error disappeared:
Oh I see. @SabadashDenis Can you check if WebGL enable this feature by default? This might be the actual issue.
Yeh, it's the source of problem. Enable package in my project and ScreenCapture error dissapeared. Tried to create new project with WebGL platform, ScreenCapture package enabled by default.
So, it was my bad. I disabled unused packages in project for optimization. And after Unity-MCP setup i had compile error.
Activity
Scriptwonder commentedon Jan 17, 2026
Can we instead add asmdef for the Runtime folder to resolve the issue?
SabadashDenis commentedon Jan 18, 2026
There is already an asmdef for the Runtime folder (MCPForUnity.Runtime.asmdef). I tried adding "excludePlatforms": ["WebGL"] to it, but this doesn't solve the compilation error.
ExcludePlatforms controls whether the compiled assembly is included in the final build, but Unity still compiles the C# code for the active build target. So when a developer has WebGL selected as their active platform in Build Settings, Unity compiles Runtime scripts using the WebGL scripting backend, where ScreenCapture class doesn't exist. This results in CS0103 error even though the assembly would be excluded from the actual build.
Using #if !UNITY_WEBGL preprocessor guards also won't work properly — it would fix the compilation error, but screenshots wouldn't work in the Editor when WebGL is the active platform, since UNITY_WEBGL is defined based on the build target, not the runtime environment.
Moving ScreenshotUtility.cs to the Editor/ folder solves both problems because Editor scripts are always compiled using the desktop scripting backend, regardless of the active build target. Since MCP tools only run in the Editor anyway, this doesn't change any functionality.
Scriptwonder commentedon Jan 19, 2026
I see your point.
The naming might be confusing: runtime actually means PlayMode, as many Editor folder tools rely on APIs that can only run on editor time. I think moving to Editor is fine, but I was thinking of expanding the runtime to include a lot more runtime-runable tools in the future. Will make that change if I cannot find a better solution these two weeks.
SabadashDenis commentedon Jan 19, 2026
Ok, thanks. I created pull request yesterday. You can check it.
Fkscorpion commentedon Jan 29, 2026
Is this also related and/or will it fix this bug? Sounds like it's the same you had just with another platform.
I've opened a project with unity 6000.3.5f2 (LTS) on the Android Platform and got this:
Library\PackageCache\com.coplaydev.unity-mcp@9c2049bb148f\Runtime\Helpers\ScreenshotUtility.cs(54,13): error CS0103: The name 'ScreenCapture' does not exist in the current contextI had to manually enable the ScreenCapture Component in the PackageManager and then the error disappeared:
Scriptwonder commentedon Jan 30, 2026
Oh I see. @SabadashDenis Can you check if WebGL enable this feature by default? This might be the actual issue.
SabadashDenis commentedon Jan 31, 2026
Yeh, it's the source of problem. Enable package in my project and ScreenCapture error dissapeared. Tried to create new project with WebGL platform, ScreenCapture package enabled by default.
So, it was my bad. I disabled unused packages in project for optimization. And after Unity-MCP setup i had compile error.
Scriptwonder commentedon Jan 31, 2026
Thank you for double checking! Will add notes in the GUI/Reference to let user know that.