CoplayDev/unity-mcp · error · ValueError

set-pixels is required

Error message

set-pixels is required

What it means

Thrown by _normalize_set_pixels() in the texture CLI when the set-pixels option is omitted entirely (value is None). It is the first guard in the normalizer and signals that the caller invoked a set-pixels-based texture command without supplying the payload the command requires. The error is a pure input-validation failure, not a network or Unity-side problem.

Source

Thrown at Server/src/cli/commands/texture.py:178

        if value.startswith("base64:"):
            return value
        trimmed = value.strip()
        if trimmed.startswith("[") and trimmed.endswith("]"):
            value = try_parse_json(trimmed, context)
        else:
            return f"base64:{value}"
    if isinstance(value, list):
        expected_count = width * height
        if len(value) != expected_count:
            raise ValueError(
                f"{context} must have {expected_count} entries, got {len(value)}")
        return [_normalize_color(pixel, f"{context} pixel") for pixel in value]
    raise ValueError(f"{context} must be a list or base64 string")


def _normalize_set_pixels(value: Any) -> dict[str, Any]:
    if value is None:
        raise ValueError("set-pixels is required")
    if isinstance(value, str):
        value = try_parse_json(value, "set-pixels")
    if not isinstance(value, dict):
        raise ValueError("set-pixels must be a JSON object")

    result: dict[str, Any] = dict(value)

    if "pixels" in value:
        width = value.get("width")
        height = value.get("height")
        if width is None or height is None:
            raise ValueError(
                "set-pixels requires width and height when pixels are provided")
        width = int(width)
        height = int(height)
        if width <= 0 or height <= 0:
            raise ValueError("set-pixels width and height must be positive")
        result["width"] = width

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Supply the set-pixels payload: `--set-pixels '{"color":"#FF0000","width":2,"height":2}'`.
  2. If calling the normalizer programmatically, ensure the value argument is a dict (or a JSON string), never None.
  3. Check the texture subcommand help (`unity-mcp texture set-pixels --help`) to confirm the required option name and JSON shape.

Example fix

// before
unity-mcp texture set-pixels Assets/Tex.png
// after
unity-mcp texture set-pixels Assets/Tex.png --set-pixels '{"color":"#FF0000","width":2,"height":2}'
Defensive patterns

Strategy: validation

Validate before calling

import json
sp = opts.get("set-pixels")
if sp is None:
    raise SystemExit("set-pixels is required")
if isinstance(sp, str):
    sp = json.loads(sp)
if not isinstance(sp, dict):
    raise SystemExit("set-pixels must be a JSON object")

Type guard

def is_set_pixels_payload(v) -> bool:
    if isinstance(v, str):
        try:
            v = json.loads(v)
        except json.JSONDecodeError:
            return False
    return isinstance(v, dict)

Try / catch

try:
    normalized = _normalize_set_pixels(value)
except ValueError as e:
    print_error(str(e)); sys.exit(1)

Prevention

When it happens

Trigger: Running a CLI/programmatic call that routes through _normalize_set_pixels with the set-pixels argument unset, e.g. `unity-mcp texture set-pixels <path>` with no --set-pixels option, or calling the normalizer directly with None. Any code path that constructs the params dict but omits the set-pixels key.

Common situations: A developer forgets the --set-pixels flag, or a script building the texture command conditionally assigns the option and the condition is false, leaving it None. Common when copy-pasting an example command and trimming arguments.

Related errors


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