Parts

PM.Parts patches part definitions: pods, engines, tanks, decouplers, wheels, and everything else you place in the editor. It is the biggest typed module because a part is the biggest asset.

A part definition is a tree. The part has top-level fields (mass, maxTemp, crashTolerance, attach nodes, editor category). It holds a set of modules (Module_Engine, Module_Deployable, Module_Drag, and so on), each module holds one or more data entries (Data_Engine, Data_Deployable), and the data entries hold the actual numbers you usually want to change.

Patching a part

PM.Parts:Patch(name) registers a patch against parts. Restrict it to specific parts with :Named(...), using the part's id (heatshield_2v_inflatable, eva_kerbal, and so on). Inside Do, top-level fields are plain assignments:

PM.Parts:Patch("KerbalImpactToleranceFix")
        :Named("eva_kerbal")
        :Do(function(part)
            part.crashTolerance = 30.0
        end)

To reach a value nested in a module, use the module and data helpers below.

The pages

  • Modules covers AddModule, PatchModule, EnsureModule, RemoveModule, and HasModule: how to add, edit, and remove the modules on a part.

  • Module data covers the same methods one level down, on the Data_* entries inside a module, where most of a part's real settings live.

  • Engine modes covers the typed helper for engines that have more than one mode (for example a switchable multi-mode engine).

  • Resource containers covers adding fuel and other resource storage to a part with a single call.

Changing parts for some campaigns only

To change parts only in campaigns that have one of your features on, patch the parts in place. Gate the patch on the feature. Campaigns without the feature keep the original parts. When a vessel in a save loads, it gets the part values of its campaign.

This is the antenna patch of the 2.5x Kerbolar System. It gives 2.5 times the range to every part that has a transmitter. It applies only in campaigns that have the Antennas feature of the mod on. It does not change other parts:

PM:WithFeature("Antennas", function()
    PM.Parts:Patch("RescaleAntennas")
        :Late()
        :Has("Module_DataTransmitter")
        :Do(function(part)
            local transmitter = part.Module_DataTransmitter.Data_Transmitter
            transmitter.CommunicationRange = transmitter.CommunicationRange * 2.5
        end)
end)

:Has("Module_DataTransmitter") works because the modules of a part are keys on the part. The gate selects the parts that the patch changes.

PM.Parts:Duplicate(source, newName) copies parts. Use it to make a new part from an existing part. A copy keeps its partName. Give the copy a new partName in the callback, or the game sees two definitions of the same part. A copy with a new name does not find its model and icon by name. Set PrefabAddress and IconAddress to the addresses of the original (<original>.prefab and <original>_icon.png), unless your mod ships its own. See Copying an existing asset.

Finding the field you want

A part has well over a hundred fields spread across its modules. This module documents the forms and the common edits, not every field. The full field list for a part, a module, or a data entry is in the pm-parts.d.lua stub, which surfaces as autocomplete and hover docs once you have set up your editor. When in doubt, type a dot and read what the editor offers.