# Missions

`PM.Missions` patches mission definitions: the agency contracts and tutorial steps that drive exploration mode. Missions are the second-largest typed module because a mission is a small state machine, not a flat record.

A mission has content branches (what happens on submit, on completion, and so on), each branch holds **actions** that fire when the branch runs, and branches advance based on **conditions**. The typed module gives you builders for both.

## Patching a mission

`PM.Missions:Patch(name)` registers a patch against missions, targeted with `:Named(...)` using the mission id (`KSP2Mission_Main_Kerbin_03` and so on). A common edit is appending an action to a branch:

```lua
PM.Missions:Patch("MoonLandingActivation")
           :Named("KSP2Mission_Main_Mun_01")
           :Do(function(mission)
               mission.ContentBranches.OnSubmit.actions:Append(
                   PM.Missions:Action("ActivateMissionAction", function(action)
                       action.TargetMissionID = "KSP2Mission_Secondary_Kerbin_KerbinTourSOI"
                       action.MissionOwner = "Agency"
                   end))
           end)
```

## The pages

* [Conditions](/doc/conditions-fmWJskmwWx) covers the `And`, `Or`, and `Not` builders that compose the logic deciding when a branch advances.
* [Actions](/doc/actions-6KiGnOYRI7) covers `PM.Missions:Action`, the content branches, and how actions are resolved from their registered type names.
* [Stages](/doc/stages-gzdWt9V4LU) covers building mission stages, the stage list, and rewards.

## Type lookups

Missions reference C# types by name (action types, property watchers, messages). The module exposes `PM.Missions:Action(type, callback)` to build an action, and `PM.Missions:GetPropertyWatcher(name)` and `PM.Missions:GetMessage(name)` to resolve the other two. The available type names live in the `pm-missions.d.lua` stub and in autocomplete once your [editor is set up](/doc/setting-up-your-editor-UScg880clw).

## Scope

Missions are quite intricate and involve a lot of self referencing and cross referencing outside of them, patching them is generally fine for smaller tuning edits/or getting your missions to follow them. However, it is not recommended to use patch manager to make new missions, that is best left to the Unity SDK.

---

**Documents**

- [Conditions](https://docs.ksp2redux.org/s/0a4a3e31-0b40-48e0-bd81-e14856f80d3d/doc/conditions-fmWJskmwWx)
- [Actions](https://docs.ksp2redux.org/s/0a4a3e31-0b40-48e0-bd81-e14856f80d3d/doc/actions-6KiGnOYRI7)
- [Stages](https://docs.ksp2redux.org/s/0a4a3e31-0b40-48e0-bd81-e14856f80d3d/doc/stages-gzdWt9V4LU)