tweakdefs vs tweakunits in BAR: what is the difference

Two different ways to modify unit behavior in Beyond All Reason, and when to use each one for local tests and lobby-hosted games.

Tags: beyond all reason, tweakdefs, tweakunits, modding, unitdefs, lobby commands

How tweakunits works

tweakunits passes through a table merge function in unitdefs_post. The game takes your override values and merges them into existing unit definitions. This produces cleaner results for simple stat changes like health, damage, or build speed.

Players can put unit names directly in the tweak box in the lobby. The merge process handles subtables and nested properties automatically. This works well for bulk changes across many units.

How tweakdefs works

tweakdefs runs as its own function without table appending. It gives direct access to the full UnitDefs table as Lua code. This matters when the modification needs conditional logic or needs to iterate over entries.

The tradeoff is syntax sensitivity. Tweakdefs expects valid Lua, so missing brackets, wrong table structure, or nil dereferences cause errors. Tweakunits is more forgiving because the merge layer catches common mistakes.

Shield interception and tweak testing

One concrete example involves shield interception masks. The engine adds interception masks automatically based on weapon type. Adding them manually in a tweak creates conflicts. The T3 shield uses interceptedByShieldType 1024, though the engine handles most of this behind the scenes.

Testing shield interactions in custom scenarios before deploying them saves debugging time. The Spring RTS WeaponDef reference documents interception types.

Which one to pick

Creed of Champions

Experimenting with game mechanics builds intuition that translates directly to match play. Players who understand why shields intercept certain weapons make smarter unit compositions. Learning without pressure is what keeps people around:

[Crd] Having a space like here that offers a community, trainings, events, and the guarantee to not be judged or insulted by fellow members is really precious. Keeping the game safe, and more importantly, fun.