Text assets

Text-asset patches change JSON-backed game content while it is loaded. They can edit existing definitions or add new content without replacing the complete source asset.

Common targets include parts, resources, planets, science definitions, missions, tech nodes, variants, and audio definitions.

Getting started

Start with Getting Started for the patch-file layout, editor support, and a first working patch.

Core Concepts explains the patch lifecycle, asset targeting, callbacks, features, dependencies, ordering, JSON values, configuration, and pm_summary.log.

APIs and typed modules

  • Generic JSON API patches any supported JSON-backed asset directly.

  • Typed Modules provide helpers for parts, missions, planets, resources, science, V-SwiFT variants, and audio.

  • Advanced Topics covers shared Lua modules, cross-mod compatibility, C# extensions, converters, and caching.

  • Reference contains the LuaPatch cheat sheet, enum values, and glossary.

Script globals

Patch scripts receive several useful globals:

  • PM registers patches through APIs such as PM.Parts:Patch(...), PM.Planets:Patch(...), and PM.JSON:Patch(...).

  • J creates JSON values that cannot be represented directly by ordinary Lua tables.

  • ModId identifies the current mod.

  • Location provides the patch location.

  • Config reads the mod's configuration.

  • CampaignConfig reads the settings that each campaign keeps.

  • Features reads the active feature set.

  • Enabled tells whether the mod is on in the active feature set.

  • Log writes diagnostic messages.

Use Features and Enabled only in runtime code. To gate patches, use :Feature.

See Working with JSON, File layout and discovery, and Config integration for details.

Minimal example

This patch finds the part named eva_kerbal and changes its crash tolerance:

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

:Patch gives the patch a stable name, :Named selects the target, and :Do applies the change.