{"record":{"id":"e5bf0c6315ea1f23","repo":"CoplayDev/unity-mcp","slug":"hostview-gettype-fullname-grabpixels-rendertex","errorCode":null,"errorMessage":"{hostView.GetType().FullName}.GrabPixels(RenderTexture, Rect)","messagePattern":"(.+?)\\.GrabPixels\\(RenderTexture, Rect\\)","errorType":"exception","errorClass":"MissingMethodException","httpStatus":null,"severity":"critical","filePath":"MCPForUnity/Editor/Helpers/EditorWindowScreenshotUtility.cs","lineNumber":197,"sourceCode":"\n        private static Texture2D CaptureViewRect(SceneView sceneView, Rect viewportRectPixels)\n        {\n            object hostView = GetHostView(sceneView);\n            if (hostView == null)\n                throw new InvalidOperationException(\"Failed to resolve Scene view host view.\");\n\n            // GrabPixels is an internal extern on GUIView (parent of HostView), present since at least Unity 2021.1.\n            // See: UnityCsReference/Editor/Mono/GUIView.bindings.cs — `internal extern void GrabPixels(RenderTexture, Rect)`\n            // If Unity removes this, the MissingMethodException below keeps the failure explicit.\n            MethodInfo grabPixels = hostView.GetType().GetMethod(\n                \"GrabPixels\",\n                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,\n                null,\n                new[] { typeof(RenderTexture), typeof(Rect) },\n                null);\n\n            if (grabPixels == null)\n                throw new MissingMethodException($\"{hostView.GetType().FullName}.GrabPixels(RenderTexture, Rect)\");\n\n            int width = Mathf.RoundToInt(viewportRectPixels.width);\n            int height = Mathf.RoundToInt(viewportRectPixels.height);\n\n            RenderTexture rt = null;\n            RenderTexture previousActive = RenderTexture.active;\n            try\n            {\n                rt = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32)\n                {\n                    antiAliasing = 1,\n                    filterMode = FilterMode.Bilinear,\n                    hideFlags = HideFlags.HideAndDontSave,\n                };\n                rt.Create();\n\n                grabPixels.Invoke(hostView, new object[] { rt, viewportRectPixels });\n","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/MCPForUnity/Editor/Helpers/EditorWindowScreenshotUtility.cs#L179-L215","documentation":"CaptureViewRect() looks up the internal 'GrabPixels(RenderTexture, Rect)' method on the host view's type via reflection. This method exists on GUIView (parent of HostView) since at least Unity 2021.1. If the method is not found (Unity removed or renamed it), it throws MissingMethodException with the full type name and expected signature. This is a forward-compatibility guard: the failure is explicit rather than a silent NullReferenceException.","triggerScenarios":"A Unity version (likely future, post-6.x/CoreCLR) where GrabPixels has been removed, renamed, or its signature changed. This is the highest-risk error for long-term maintenance as it depends on an internal, non-public API.","commonSituations":"Upgrading Unity to a version that refactors the GUIView pixel capture internals. Running on a Unity preview/beta that changed internal editor APIs. CoreCLR 2026 migration that restructures editor bindings.","solutions":["Check the Unity version's release notes for editor API changes to GUIView/GrabPixels.","Inspect the actual method signature: use reflection to enumerate methods on the host view type and find the replacement.","If GrabPixels was renamed, update the GetMethod call in EditorWindowScreenshotUtility.cs with the new name.","If removed entirely, implement an alternative capture path (e.g., Camera.Render into a RenderTexture).","Run tools/check-unity-versions.sh to compile-check against the CI version matrix after changes."],"exampleFix":"// before\nMethodInfo grabPixels = hostView.GetType().GetMethod(\"GrabPixels\", ...);\nif (grabPixels == null)\n    throw new MissingMethodException(...);\n\n// after\nMethodInfo grabPixels = hostView.GetType().GetMethod(\"GrabPixels\", ...)\n    ?? hostView.GetType().GetMethod(\"GrabPixelsInto\", ...); // hypothetical renamed API\nif (grabPixels == null)\n    throw new MissingMethodException(...);","handlingStrategy":"type-guard","validationCode":"Type guiViewType = hostView.GetType();\nMethodInfo grab = guiViewType.GetMethod(\"GrabPixels\",\n    BindingFlags.Instance | BindingFlags.NonPublic,\n    null, new[] { typeof(RenderTexture), typeof(Rect) }, null);\nif (grab == null) { /* fall back to Camera.Render-based capture */ }","typeGuard":"public static bool SupportsGrabPixels(object hostView)\n{\n    if (hostView == null) return false;\n    return hostView.GetType().GetMethod(\"GrabPixels\",\n        BindingFlags.Instance | BindingFlags.NonPublic,\n        null, new[] { typeof(RenderTexture), typeof(Rect) }, null) != null;\n}","tryCatchPattern":"try { CaptureViewRect(sceneView, rect); }\ncatch (MissingMethodException ex)\n{ Debug.LogError($\"GrabPixels unavailable in this Unity version: {ex.Message}. Use alternative capture.\"); }","preventionTips":["Run tools/check-unity-versions.sh after Unity upgrades to verify GrabPixels still exists.","Maintain a fallback capture path (Camera.Render into RenderTexture) for when GrabPixels is removed.","Monitor Unity upgrade guides for editor internal API changes.","Pin to tested Unity versions for production use of scene capture."],"tags":["screenshot","reflection","internal-api","unity-version","forward-compat","breaking-change"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}