Anuken/Mindustry · error · IllegalArgumentException
No constructor set up for unit '{name}', add this argument t
Error message
No constructor set up for unit '{name}', add this argument to your units field: `constructor = UnitEntity::create` What it means
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.
Source
Thrown at core/src/mindustry/type/UnitType.java:1220
for(Weapon weapon : weapons){
for(var part : weapon.parts){
part.getOutlines(out);
}
}
for(var part : parts){
part.getOutlines(out);
}
}
public boolean needsBodyOutline(){
return alwaysCreateOutline;
}
@Override
public void createIcons(MultiPacker packer){
super.createIcons(packer);
if(constructor == null) throw new IllegalArgumentException("No constructor set up for unit '" + name + "', add this argument to your units field: `constructor = UnitEntity::create`");
sample = constructor.get();
var toOutline = new Seq<TextureRegion>();
getRegionsToOutline(toOutline);
for(var region : toOutline){
if(region instanceof AtlasRegion atlas && !Core.atlas.has(atlas.name + "-outline")){
String regionName = atlas.name;
Pixmap outlined = Pixmaps.outline(packer.get(region), outlineColor, outlineRadius);
Drawf.checkBleed(outlined);
packer.add(PageType.main, regionName + "-outline", outlined);
outlined.dispose();
}
}
View on GitHub (pinned to f695ad7e60)
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.
Example fix
// before: UnitType with no constructor reaches createIcons -> throws // after: set constructor = UnitEntity::create (or the appropriate factory) in the type's constructor
Defensive patterns
Strategy: validation
Validate before calling
// Guard createIcons against missing constructors.
if(constructor == null) {
throw new IllegalArgumentException("No constructor for unit '" + name + "'");
} Type guard
boolean hasConstructor(UnitType t){ return t != null && t.constructor != null; } Try / catch
try {
type.createIcons(packer);
} catch(IllegalArgumentException e) {
if(e.getMessage().startsWith("No constructor set up for unit")) { /* assign constructor */ }
else throw e;
} Prevention
- 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.
When it happens
Trigger: A UnitType reaches createIcons with constructor == null (no factory assigned).
Common situations: 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.
Related errors
- Calling getPixmap outside of createIcons is not supported!
- No constructor set up for unit '@': Assign `constructor = [y
- Invalid class ID for `@` detected (found: @). Potential fixe
- Max image size exceeded
- Mod is not loaded yet (or missing)!
AI-assisted analysis of Anuken/Mindustry@f695ad7e60 (2026-08-14).
Data as JSON: /api/errors/a2ec335ee2d091a6.
Report an issue: GitHub.