Anuken/Mindustry · error · RuntimeException

Unit '${name}' has an incorrect type. Types must be strings.

Error message

Unit '${name}' has an incorrect type. Types must be strings.

What it means

While constructing a UnitType, if a "type" field is present in the JSON but its value is not a JSON string, the parser throws. The "type" field selects the unit's entity constructor (flying, mech, legs, etc.), so a non-string value (number, object, array) is unparseable.

Source

Thrown at core/src/mindustry/mod/ContentParser.java:631

            return block;
        },
        ContentType.unit, (TypeParser<UnitType>)(mod, name, value) -> {
            readBundle(ContentType.unit, name, value);

            UnitType unit;
            if(!allowPatching || locate(ContentType.unit, name) == null){

                unit = make(resolve(value.getString("template", ""), UnitType.class), mod + "-" + name);

                if(value.has("template")){
                    value.remove("template");
                }

                var typeVal = value.get("type");
                if(unit.constructor == null || typeVal != null){
                    if(typeVal != null && !typeVal.isString()){
                        throw new RuntimeException("Unit '" + name + "' has an incorrect type. Types must be strings.");
                    }

                    unit.constructor = unitType(typeVal);
                }
            }else{
                unit = locate(ContentType.unit, name);
            }

            currentContent = unit;
            read(() -> {
                unit.beforeParse();
                //add reconstructor type
                if(value.has("requirements")){
                    JsonValue rec = value.remove("requirements");

                    UnitReq req = parser.readValue(UnitReq.class, rec);

                    if(req.block instanceof Reconstructor r){

View on GitHub (pinned to f695ad7e60)

Solutions

  1. Make the "type" value a string literal matching a supported unit type (see error 92).
  2. Omit "type" entirely if the template's default constructor is acceptable.
  3. Validate that "type" is a quoted string before submitting the mod.

Example fix

// before
"type": 1
// after
"type": "flying"
Defensive patterns

Strategy: validation

Validate before calling

JsonValue t = value.get("type");
if(t != null && !t.isString()){
    throw new IllegalStateException("'type' must be a string, got " + t.type());
}

Type guard

// Narrow a JsonValue to a string 'type' field.
String unitType(JsonValue v){
    JsonValue t = v.get("type");
    return (t != null && t.isString()) ? t.asString() : null;
}

Prevention

When it happens

Trigger: A unit JSON provides "type": 3 or "type": {"name":"flying"} instead of "type": "flying". The guard fires only when typeVal != null && !typeVal.isString().

Common situations: Confusing "type" (entity move type) with "template" (parent class); pasting a numeric ID from a lookup table; malformed auto-generated JSON.

Related errors


AI-assisted analysis of Anuken/Mindustry@f695ad7e60 (2026-08-14). Data as JSON: /api/errors/a71101d8384e159d. Report an issue: GitHub.