CoplayDev/unity-mcp · error · ValueError

{context} values must be numeric, got {value}

Error message

{context} values must be numeric, got {value}

What it means

Raised by _normalize_color (texture.py:138) when the value is a list/tuple of 4 components (or 3 extended to 4) but a component cannot be converted via float()/int() (TypeError or ValueError). The 'context' labels the field (e.g. 'color values must be numeric...'). This is the list/tuple branch; correct length but non-numeric contents triggers it.

Source

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

                else:
                    color.append(1.0 if _is_normalized_color(color) else 255)
                if _is_normalized_color(color):
                    return [int(round(float(c) * 255)) for c in color]
                return [int(c) for c in color]
            except (TypeError, ValueError):
                raise ValueError(f"{context} dict values must be numeric, got {value}")
        raise ValueError(f"{context} dict must have 'r', 'g', 'b' keys, got {list(value.keys())}")

    if isinstance(value, (list, tuple)):
        if len(value) == 3:
            value = list(value) + [1.0 if _is_normalized_color(value) else 255]
        if len(value) == 4:
            try:
                if _is_normalized_color(value):
                    return [int(round(float(c) * 255)) for c in value]
                return [int(c) for c in value]
            except (TypeError, ValueError):
                raise ValueError(
                    f"{context} values must be numeric, got {value}")
        raise ValueError(
            f"{context} must have 3 or 4 components, got {len(value)}")

    raise ValueError(f"{context} must be a list or hex string")


def _normalize_palette(value: Any, context: str) -> list[list[int]]:
    if value is None:
        return []
    if isinstance(value, str):
        value = try_parse_json(value, context)
    if not isinstance(value, list):
        raise ValueError(f"{context} must be a list of colors")
    return [_normalize_color(color, f"{context} item") for color in value]


def _normalize_pixels(value: Any, width: int, height: int, context: str) -> list[list[int]] | str:

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Ensure every list element is a number (0-255 or normalized 0-1).
  2. Unquote numeric elements and replace nulls with explicit numbers.
  3. Validate the array contains only int/float before passing.

Example fix

# before
unity-mcp texture create Assets/Tex.png --color '["red",0,0,255]'

# after
unity-mcp texture create Assets/Tex.png --color '[255,0,0,255]'
Defensive patterns

Strategy: type-guard

Validate before calling

# Python - before normalizing a list color
if isinstance(value, (list, tuple)):
    if not all(isinstance(c, (int, float)) and not isinstance(c, bool) for c in value):
        raise ValueError(f"{context} values must be numeric, got {value}")

Type guard

def is_numeric_color_list(v) -> bool:
    return isinstance(v, (list, tuple)) and all(isinstance(c, (int, float)) and not isinstance(c, bool) for c in v)

Try / catch

try:
    color = _normalize_color(value, context)
except ValueError as e:
    print_error(str(e)); sys.exit(1)

Prevention

When it happens

Trigger: Passing --color '["red",0,0]' or --color '[255,0,null]' or a 4-element array with a string/null in any slot. Same for palette items, pixels, and set-pixels color supplied as a list.

Common situations: A JSON array where one channel was quoted or left null; mixing a color name string into an otherwise numeric list; copy-pasting partial data.

Related errors


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