CoplayDev/unity-mcp · error · ValueError
import_settings must be a JSON object
Error message
import_settings must be a JSON object
What it means
Thrown by _normalize_import_settings() when, after optional JSON-string parsing, the value is not a dict. Import settings are a map of key/value pairs, so a non-object (array, number, string) is rejected before any field mapping occurs.
Source
Thrown at Server/src/cli/commands/texture.py:251
return value
if isinstance(value, (int, float)) and value in (0, 1, 0.0, 1.0):
return bool(value)
if isinstance(value, str):
lowered = value.strip().lower()
if lowered in _TRUE_STRINGS:
return True
if lowered in _FALSE_STRINGS:
return False
raise ValueError(f"{name} must be a boolean")
def _normalize_import_settings(value: Any) -> dict[str, Any]:
if value is None:
return {}
if isinstance(value, str):
value = try_parse_json(value, "import_settings")
if not isinstance(value, dict):
raise ValueError("import_settings must be a JSON object")
result: dict[str, Any] = {}
if "texture_type" in value:
result["textureType"] = _map_enum(
value["texture_type"], _TEXTURE_TYPES)
if "texture_shape" in value:
result["textureShape"] = _map_enum(
value["texture_shape"], _TEXTURE_SHAPES)
for snake, camel in [
("srgb", "sRGBTexture"),
("alpha_is_transparency", "alphaIsTransparency"),
("readable", "isReadable"),
("generate_mipmaps", "mipmapEnabled"),
("compression_crunched", "crunchedCompression"),
]:
if snake in value:View on GitHub (pinned to c21bf496bc)
Solutions
- Wrap settings in a JSON object: `--import-settings '{"texture_type":"sprite"}'`.
- Validate the JSON parses to a dict with `python -c "import json,sys; print(type(json.loads(sys.argv[1])))" '<value>'`.
- Leave --import-settings off entirely to use Unity defaults.
Example fix
// before
--import-settings 'sprite'
// after
--import-settings '{"texture_type":"sprite"}' Defensive patterns
Strategy: type-guard
Validate before calling
import json
if isinstance(value, str):
value = json.loads(value)
if not isinstance(value, dict):
raise ValueError("import_settings must be a JSON object") Type guard
def is_import_settings_obj(v) -> bool:
if isinstance(v, str):
try:
v = json.loads(v)
except json.JSONDecodeError:
return False
return isinstance(v, dict) Try / catch
try:
settings = _normalize_import_settings(raw)
except ValueError as e:
print_error(str(e)); sys.exit(1) Prevention
- Wrap import settings in a JSON object.
- Omit --import-settings to accept Unity defaults.
When it happens
Trigger: Passing --import-settings as a JSON array or scalar, e.g. `--import-settings '[]'` or `--import-settings '"sprite"'`, or calling the normalizer with a list. Also when a quoted JSON string parses to a scalar instead of an object.
Common situations: A developer passes a single import type string directly instead of an object, or misquotes the JSON so it becomes a scalar. Common when adapting an example that used a bare value.
Related errors
- set-pixels must be a JSON object
- {name} must be a boolean
- set-pixels is required
- set-pixels requires width and height when pixels are provide
- set-pixels width and height must be positive
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/2cd3fbecc9a123d0.
Report an issue: GitHub.