CoplayDev/unity-mcp · error · ValueError
set-pixels requires 'color' or 'pixels'
Error message
set-pixels requires 'color' or 'pixels'
What it means
Thrown by _normalize_set_pixels() when the object contains neither 'pixels' nor 'color'. The set-pixels operation must write something to the texture, so at least one of these content keys is mandatory; an object with only metadata (width, height, x, y) is rejected.
Source
Thrown at Server/src/cli/commands/texture.py:205
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
result["height"] = height
result["pixels"] = _normalize_pixels(
value["pixels"], width, height, "set-pixels pixels")
if "color" in value:
result["color"] = _normalize_color(value["color"], "set-pixels color")
if "pixels" not in value and "color" not in value:
raise ValueError("set-pixels requires 'color' or 'pixels'")
if "x" in value:
result["x"] = int(value["x"])
if "y" in value:
result["y"] = int(value["y"])
if "width" in value and "pixels" not in value:
result["width"] = int(value["width"])
if "height" in value and "pixels" not in value:
result["height"] = int(value["height"])
return result
def _map_enum(value: Any, mapping: dict[str, str]) -> Any:
if isinstance(value, str):
key = value.lower()
return mapping.get(key, value)View on GitHub (pinned to c21bf496bc)
Solutions
- Add a color key: `--set-pixels '{"color":"#FF0000","width":2,"height":2}'`.
- Or add a pixels array with matching dimensions.
- If you intended a no-op, omit the --set-pixels option entirely rather than passing an empty object.
Example fix
// before
--set-pixels '{"width":2,"height":2,"x":0,"y":0}'
// after
--set-pixels '{"color":"#FF0000","width":2,"height":2,"x":0,"y":0}' Defensive patterns
Strategy: validation
Validate before calling
if "pixels" not in sp and "color" not in sp:
raise ValueError("set-pixels requires 'color' or 'pixels'") Type guard
def has_content_key(v: dict) -> bool:
return "color" in v or "pixels" in v Try / catch
try:
payload = _normalize_set_pixels(sp)
except ValueError as e:
print_error(str(e)); sys.exit(1) Prevention
- Always include a color or pixels key.
- Omit --set-pixels entirely for a no-op rather than an empty object.
When it happens
Trigger: Passing `--set-pixels '{"width":2,"height":2,"x":0,"y":0}'` with no pixels or color. Providing an empty object, or only coordinate/dimension keys.
Common situations: A developer supplies dimensions and offsets expecting a clear operation, not realizing set-pixels requires explicit content. Or a templating bug omits the content key.
Related errors
- set-pixels is required
- set-pixels must be a JSON object
- set-pixels requires width and height when pixels are provide
- set-pixels width and height must be positive
- {name} must be a boolean
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/88f70ddc884eaacd.
Report an issue: GitHub.