{"record":{"id":"a2ec335ee2d091a6","repo":"Anuken/Mindustry","slug":"no-constructor-set-up-for-unit-name-add-this","errorCode":null,"errorMessage":"No constructor set up for unit '{name}', add this argument to your units field: `constructor = UnitEntity::create`","messagePattern":"No constructor set up for unit '(.+?)', add this argument to your units field: `constructor = UnitEntity::create`","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/mindustry/type/UnitType.java","lineNumber":1220,"sourceCode":"        for(Weapon weapon : weapons){\n            for(var part : weapon.parts){\n                part.getOutlines(out);\n            }\n        }\n        for(var part : parts){\n            part.getOutlines(out);\n        }\n    }\n\n    public boolean needsBodyOutline(){\n        return alwaysCreateOutline;\n    }\n\n    @Override\n    public void createIcons(MultiPacker packer){\n        super.createIcons(packer);\n\n        if(constructor == null) throw new IllegalArgumentException(\"No constructor set up for unit '\" + name + \"', add this argument to your units field: `constructor = UnitEntity::create`\");\n\n        sample = constructor.get();\n\n        var toOutline = new Seq<TextureRegion>();\n        getRegionsToOutline(toOutline);\n\n        for(var region : toOutline){\n            if(region instanceof AtlasRegion atlas && !Core.atlas.has(atlas.name + \"-outline\")){\n                String regionName = atlas.name;\n                Pixmap outlined = Pixmaps.outline(packer.get(region), outlineColor, outlineRadius);\n\n                Drawf.checkBleed(outlined);\n\n                packer.add(PageType.main, regionName + \"-outline\", outlined);\n                outlined.dispose();\n            }\n        }\n","sourceCodeStart":1202,"sourceCodeEnd":1238,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/core/src/mindustry/type/UnitType.java#L1202-L1238","documentation":"UnitType.createIcons needs a sample entity (sample = constructor.get()) to generate outlines, so it throws IllegalArgumentException if constructor is still null at icon-generation time. This is the same root cause as the init-time check (117) but fires later during createIcons.","triggerScenarios":"A UnitType reaches createIcons with constructor == null (no factory assigned).","commonSituations":"A unit type skipped/deferred the init-time check, or constructor was set conditionally and left null; icon generation runs for a half-defined type.","solutions":["Assign constructor for every UnitType (same fix as 117).","Ensure constructor is set before both init and createIcons phases.","Avoid defining UnitTypes that are never fully configured."],"exampleFix":"// before: UnitType with no constructor reaches createIcons -> throws\n// after: set constructor = UnitEntity::create (or the appropriate factory) in the type's constructor","handlingStrategy":"validation","validationCode":"// Guard createIcons against missing constructors.\nif(constructor == null) {\n    throw new IllegalArgumentException(\"No constructor for unit '\" + name + \"'\");\n}","typeGuard":"boolean hasConstructor(UnitType t){ return t != null && t.constructor != null; }","tryCatchPattern":"try {\n    type.createIcons(packer);\n} catch(IllegalArgumentException e) {\n    if(e.getMessage().startsWith(\"No constructor set up for unit\")) { /* assign constructor */ }\n    else throw e;\n}","preventionTips":["Set constructor on every UnitType so both init and createIcons pass.","Avoid half-defined UnitTypes that reach icon generation.","Reuse the same fix as the init-time constructor check."],"tags":["modding","units","entities","textures","lifecycle"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}