BAR modding: unit cloning patterns and removing corpse clutter

Two practical modding patterns — cloning base units to create custom variants and cleaning up battlefield debris by disabling unit corpses.

Tags: BAR modding, table.copy, no corpse, custom units, spectator HUD

Spectator economy stats are built-in

Economy statistics visible when spectating or watching replays come with the base game. No download or widget installation required. The HUD automatically displays metal and energy income, expenditure, and storage when spectating. If the display is not showing, check that the spectator HUD widgets are enabled rather than assuming a missing download.

Removing unit corpses for clean battlefields

The pattern if ud.corpse then ud.corpse = nil end removes the wreckage model that units leave behind when destroyed. Running this through the full UnitDefs table makes every unit die without leaving any debris — no metal to reclaim, no visual clutter. This is useful for custom game modes where reclaim should not exist or for cleaner-looking matches. The tradeoff is that removing corpses removes a core economic mechanic — dead units can no longer be reclaimed for metal, which fundamentally changes the game's economy flow.

Unit cloning with table.copy patterns

Creating multiple custom units from the same base definition uses a clean looping pattern:

local customUnits = {
  { custom = "leegmechc", base = "leegmech" },
  { custom = "legpedec", base = "legpede" },
  { custom = "legkeresc", base = "legkeres" },
}

for _, unit in ipairs(customUnits) do
  UnitDefs[unit.custom] = table.copy(UnitDefs[unit.base])
  -- apply any additional customizations here
end

This pattern scales well — add entries to the table without changing the loop logic. After the copy, apply any custom modifications to specific units individually. The table.copy function ensures a deep clone rather than a reference assignment, meaning the cloned unit can be modified independently without affecting the original.

Creed of champions

Clean modding practices help everyone learn faster. Creed of Champions includes players who share working code patterns and help newcomers avoid common mistakes. Win with skill, teamwork, and respect.

[Crd] One of the few places where you can for sure coordinate with people in matches with a good supportive attitude. Everybody tends to be understanding and constructive.

Advertisement