Tags: bar modding, unitdefs, weapondefs, buildoptions, tweakoptions, modoption, beyond all reason modding

Understanding BAR unitdefs_post.lua and TweakOptions

How tweakoptions fits into the startup script order, modifying buildoptions, and working with unitdefs and weapondefs in BAR modding.

Loading order matters

The file unitdefs_post.lua sits in the middle of BAR's startup script chain. Tweakoptions runs after unit definitions load but before the game fully initializes, meaning any unit property overrides from tweakoptions will override the base unitdefs. Understanding this sequence prevents wasted hours wondering why a tweak isn't taking effect.

Weapondefs and unitdefs follow slightly different processing paths. A change that works on weapon properties might not apply the same way to unit definitions because they pass through different handler stages before reaching the game state.

Removing build options from units

A common modding task involves stripping build options from specific units. The pattern looks like this: access the unit by name through UnitDefs["unitname"], check if buildoptions exist, iterate backward through the array with for i=#unit.buildoptions,1,-1, and remove matching entries with table.remove. Iterating backward matters because removing items shifts the indices.

This approach works for disabling faction-specific structures in custom scenarios. The Legion AA platform losing access to the fortress build option is one practical example where this pattern shows up.

Modoptions and techsplit

Some mod interactions break when techsplit or other modoptions are active. If a tweak stops working in certain lobbies, checking the enabled modoptions list often reveals the conflict. Disabling extra unit additions and loading units through the tweak itself provides more reliable behavior than relying on both systems at once.

Useful reference files

Creed of Champions

Creed of Champions builds competitive teams where players focus on execution and learning together. The group emphasizes cooperation over individual blame, which matters as much in matches as it does in the modding community.

[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.