CoplayDev/unity-mcp · critical · MissingMethodException

{hostView.GetType().FullName}.GrabPixels(RenderTexture, Rect

Error message

{hostView.GetType().FullName}.GrabPixels(RenderTexture, Rect)

What it means

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.

Source

Thrown at MCPForUnity/Editor/Helpers/EditorWindowScreenshotUtility.cs:197

        private static Texture2D CaptureViewRect(SceneView sceneView, Rect viewportRectPixels)
        {
            object hostView = GetHostView(sceneView);
            if (hostView == null)
                throw new InvalidOperationException("Failed to resolve Scene view host view.");

            // GrabPixels is an internal extern on GUIView (parent of HostView), present since at least Unity 2021.1.
            // See: UnityCsReference/Editor/Mono/GUIView.bindings.cs — `internal extern void GrabPixels(RenderTexture, Rect)`
            // If Unity removes this, the MissingMethodException below keeps the failure explicit.
            MethodInfo grabPixels = hostView.GetType().GetMethod(
                "GrabPixels",
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                null,
                new[] { typeof(RenderTexture), typeof(Rect) },
                null);

            if (grabPixels == null)
                throw new MissingMethodException($"{hostView.GetType().FullName}.GrabPixels(RenderTexture, Rect)");

            int width = Mathf.RoundToInt(viewportRectPixels.width);
            int height = Mathf.RoundToInt(viewportRectPixels.height);

            RenderTexture rt = null;
            RenderTexture previousActive = RenderTexture.active;
            try
            {
                rt = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32)
                {
                    antiAliasing = 1,
                    filterMode = FilterMode.Bilinear,
                    hideFlags = HideFlags.HideAndDontSave,
                };
                rt.Create();

                grabPixels.Invoke(hostView, new object[] { rt, viewportRectPixels });

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Check the Unity version's release notes for editor API changes to GUIView/GrabPixels.
  2. Inspect the actual method signature: use reflection to enumerate methods on the host view type and find the replacement.
  3. If GrabPixels was renamed, update the GetMethod call in EditorWindowScreenshotUtility.cs with the new name.
  4. If removed entirely, implement an alternative capture path (e.g., Camera.Render into a RenderTexture).
  5. Run tools/check-unity-versions.sh to compile-check against the CI version matrix after changes.

Example fix

// before
MethodInfo grabPixels = hostView.GetType().GetMethod("GrabPixels", ...);
if (grabPixels == null)
    throw new MissingMethodException(...);

// after
MethodInfo grabPixels = hostView.GetType().GetMethod("GrabPixels", ...)
    ?? hostView.GetType().GetMethod("GrabPixelsInto", ...); // hypothetical renamed API
if (grabPixels == null)
    throw new MissingMethodException(...);
Defensive patterns

Strategy: type-guard

Validate before calling

Type guiViewType = hostView.GetType();
MethodInfo grab = guiViewType.GetMethod("GrabPixels",
    BindingFlags.Instance | BindingFlags.NonPublic,
    null, new[] { typeof(RenderTexture), typeof(Rect) }, null);
if (grab == null) { /* fall back to Camera.Render-based capture */ }

Type guard

public static bool SupportsGrabPixels(object hostView)
{
    if (hostView == null) return false;
    return hostView.GetType().GetMethod("GrabPixels",
        BindingFlags.Instance | BindingFlags.NonPublic,
        null, new[] { typeof(RenderTexture), typeof(Rect) }, null) != null;
}

Try / catch

try { CaptureViewRect(sceneView, rect); }
catch (MissingMethodException ex)
{ Debug.LogError($"GrabPixels unavailable in this Unity version: {ex.Message}. Use alternative capture."); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13). Data as JSON: /api/errors/e5bf0c6315ea1f23. Report an issue: GitHub.