BAR tweakdefs and unitdefs quick reference for modders

Getting lost in Beyond All Reason modding tables comes with the territory. tweakdefs and unitdefs follow different conventions and tripping over nil fields or mismatched keys will eat an afternoon fast. Here is the clean version of what matters.

Tags: bar modding, tweakdefs, unitdefs, lua widgets, spring engine, unit definitions, beyond all reason

Where widget code actually lives

All BAR widgets sit in the luaui/Widgets/ folder of the game repository. If you need reference code for how existing widgets interact with game data, the repository on GitHub is your starting point. gui_top_bar.lua is the most straightforward one to read through. The rest of the folder gives examples of how different widgets handle unit lookups, UI hooks, and spring calls. Read what similar widgets already do before building your own.

tweakdefs versus unitdefs, clear difference

Two different tables, two different indexing rules. Getting this wrong is the most common modding mistake in BAR spring engine setups.

In tweakdefs, only UnitDefs exists. It contains exactly whatever data lives in the units/xyz.lua definition files. Everything is completely unsanitized. Max health is called "maxdamage" not "health". All keys are lowercase. The table is indexed by unit name, not by number.

In widgets, both UnitDefs and UnitDefNames exist. UnitDefs is indexed by numeric ID. UnitDefNames is indexed by name and points back to the same underlying objects. Unit definitions accessed through either table carry an .id field. Health is already called "health" here. Two-word keys typically use uppercase second words like "maxHealth" rather than the raw "maxdamage" you find in tweakdefs.

Common tweakdefs mistakes to avoid

Malformed definitions break silently. Watch for missing subtables, unchecked nil values, and assumption that tweakdefs sanitizes anything. It does not. Always check whether a subtable exists before accessing nested fields. Spring will not catch bad table paths at load time. You get a nil crash when the unit spawns and the widget fires.

Do not assume numerical IDs exist in tweakdefs. They do not. If your code expects numeric indexing from tweakdefs it will fail immediately.

Building defended setups and mex walls

One reason modders reach for tweakdefs is to experiment with base layout patterns: walls with integrated turrets, defended mex lines, and eco chains. When tweaking these structures, remember that every building unit in tweakdefs still uses the raw unsanitized format. A turret placed on a wall uses the same unitdef lookup rules as any other unit. Check the actual unit file under units/ to confirm field names before coding against them.

Practical debugging steps

Creed of Champions

Creed of Champions runs a community where learning is the whole point. Modding BAR requires patience, clean testing habits, and teammates who help you iterate instead of tearing into you when something breaks. Players who build things here carry that discipline into matches too. Better builders, better teammates.

[Crd] Creed of Champions rekindled my joy in Beyond All Reason. I had burned out on the game, and the friendly, no-toxicity environment caused me to start enjoying it again.