> ## Content Index
> Fetch the complete content index at: https://simstructures.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# RimWorld Under the Hood: ThinkTree AI, Tick Scheduling & Region Pathfinding
- URL: https://simstructures.com/rimworld-under-the-hood/
- Published: 2026-08-31T16:57:07.000Z
- Updated: 2026-08-31T18:36:59.000Z
- Description: How RimWorld runs a colony of hundreds on Unity/C#: ThinkTree AI, an object-component world, staggered Rare/Long ticks, and A* pruned by a region-and-room graph.
- Author: ENGN GAME STUDIO LLC
- Tags: RimWorld, Articles

### Engine & Tech Stack

- **Engine / language:** Unity with C# on the Mono scripting backend; most 2D rendering is custom, batching meshes per map layer.
- **Map representation:** a flat 2D grid: every cell is an `IntVec3` flattened to a 1D array index (`CellIndices`), with parallel layer arrays for terrain, things (`ThingGrid`), pathability (`PathGrid`), fog, snow/filth and per-room temperature.
- **Content & modding:** everything is data-defined in XML `Def`s loaded at startup; runtime behavior is patched via Harmony.

### Core AI & Decision Making

- **Architecture:** pawn behavior runs on a hierarchical **ThinkTree**: ordered `ThinkNode`s forming a behavior-tree / utility hybrid, not a flat state machine.
- **Dispatch:** each decision walks the tree top-down: high-priority nodes (fire, threats, urgent needs, mental states) short-circuit first; otherwise it descends into work via **JobGivers** filtered and sorted by the player's per-pawn **work-priority** matrix. The winning JobGiver emits a **Job** (with `TargetA/B/C`) that a `JobDriver` executes as a sequence of Toils.

### State Management & Data Architecture

- **Model:** object-oriented **component** trees, not strict ECS. The world is a hierarchy of managers: Game → World / Map → per-map managers (`ThingGrid`, `RegionGrid`, `PathGrid`, temperature cache). Entities are `Thing`s extended by attachable `ThingComp`s and `Hediff`s.
- **Persistence:** a reflection-based serializer, **Scribe**, writes XML and resolves cross-references on load.

### Tick Scheduling & Performance Tricks

- **Staggered ticks:** a central `TickManager` spreads work across three lists: **Normal** (\~60/s at 1×), **Rare** (every 250 ticks ≈ 4.2 s) and **Long** (every 2000 ticks ≈ 33 s).
- **Why it scales:** costly simulation (temperature diffusion, plant growth, filth/deterioration, need decay) is pushed onto TickRare/TickLong so hundreds of pawns and things never update in a single frame. Game speed multiplies ticks-per-frame, not the interval.

### Pathfinding & Spatial Systems

- **Algorithm:** a custom grid **A\*** (`PathFinder`) over per-cell move costs.
- **Spatial partitioning:** a **Region + Room** system groups contiguous cells joined by portals/doors, giving near-O(1) reachability checks and fast "closest X" queries that prune A\* to relevant regions.
- **Cost matrix:** terrain move cost, doors, buildings and blueprints, plus an **avoid grid** weighting danger/enemy proximity; rooms cache temperature and gas.