Creating new BAR units and changing default commands through tweakdefs

Adding completely new units through tweakdefs is possible but has caveats. UnitDefs assignment with deepcopy works, adding to buildoptions registers the unit, but naming requires internationalization work. Here is what works and what needs attention.

Tags: BAR unit creation, tweakdefs new units, deepcopy unitdefs, customparams override, guard command widget, beyond all reason

Adding new units with deepcopy

Creating a new unit through tweakdefs starts with copying an existing unit definition. UnitDefs["newunit"] = deepcopy(UnitDefs["existingunit"]) makes a functional copy. Add the new unit name to buildoptions of labs or factories that should construct it. The unit spawns and behaves based on the copied definition.

Unit naming through internationalization

The in-game display name pulls from translation tables, not from tweakdefs directly. After creating a unit via deepcopy, the game shows a raw key like "units.names.newunit" because no translation exists. Modders have discussed adding overrideUnitName to customparams as a solution, but this is not implemented in the core system yet. Full naming requires editing the internationalization tables alongside tweak code.

Changing default right-click commands

The default right-click action for most builder units is CMD.REPAIR. To change this to CMD.GUARD or another command, write a simple widget that intercepts the right-click input and substitutes the command. Unit modes after creation from labs can also be preset through existing community solutions shared in the modding channels.

Creed of Champions

Building custom units and testing them with real players is how BAR modding stays alive. Creed provides the testing ground for that work.

[Crd] Crd is the first really comfortable community I have been a part of. Everyone is nice and kind, the atmosphere is relaxed.

Advertisement