Architecture Overview
Grid Building 5.0.8 is best understood as a node-first plugin with a composition-container / injector integration style.
Version note: This guide is validated for Grid Building 5.0.8 (maintenance stable). The core architecture is unchanged from 5.0.4; 5.0.5 fixed GBAssetResolver subdirectory scanning. See the Patch Notes for specifics.
5.0.8 consists of these main systems that work together:
| System | Purpose | Location |
|–||******-|
| GBInjectorSystem | Initializes and wires dependencies across the scene | addons/grid_building/systems/injection/ |
| GBCompositionContainer | Canonical runtime composition root for config, contexts, states, logger, actions, and templates | addons/grid_building/resources/ |
| BuildingSystem | Enters build mode, creates preview instances, runs placement setup, and commits placement | addons/grid_building/systems/building/ |
| GridTargetingSystem | Central targeting-side coordinator for targeting state/settings/path manager validation | addons/grid_building/systems/grid_targeting/ |
| GridPositioner2D | Handles mouse/keyboard cursor-to-grid positioning and visibility | addons/grid_building/systems/grid_targeting/grid_positioner/ |
| TargetingShapeCast2D | Updates GridTargetingState.target from collision queries | addons/grid_building/systems/grid_targeting/grid_positioner/ |
| ManipulationSystem | Owns move/build-manipulation workflow and manipulation state transitions | addons/grid_building/systems/manipulation/ |
| ManipulationParent | Visual transform parent for rotation/flip/preview hierarchy during manipulation | addons/grid_building/systems/manipulation/ |
5.0.4 stability note: The ManipulationSystem and BuildingSystem received significant hardening in 5.0.4. Stale state, deleted sources during active moves, and recursive cleanup edge cases are now handled safely.
5.0.8 note:
TargetingShapeCast2Drequires placed objects to havecollision_layer(what the object IS) set to the targeting layer, not justcollision_mask. See Troubleshooting.
Key Classes
State Management (in resources/states/ and systems/*/ subdirectories)
| Class | Location | Purpose |
|-|-|******|
| GBStates | resources/states/ | Container for all state (mode, targeting, building, manipulation) |
| ModeState | mode/ | Current building mode (OFF, BUILD, MANIPULATE) |
| GridTargetingState | systems/grid_targeting/ | Targeting information such as target, target map, maps, positioner, manual targeting flags, and collision exclusions |
| BuildingState | systems/building/ | Placement parent, builder ownership, and build-related runtime state |
| ManipulationState | systems/manipulation/ | Active manipulation parent and manipulation-specific runtime state |
Scene Context Nodes
| Class | Location | Purpose |
|-|-|******|
| GBLevelContext | components/ | Exports target_map, maps, and objects_parent properties; applies them via resolve_gb_dependencies() |
| GBOwner | user/ | Registers the active owner/actor in owner context |
| GBContexts | context/ | Holds indicator, owner, and systems contexts |
| GBSystemsContext | context/ | Holds references to BuildingSystem, GridTargetingSystem, ManipulationSystem; use set_system() to register |
| IndicatorContext | context/ | Holds reference to IndicatorManager |
| GBOwnerContext | user/ | Internal refcounted holding the GBOwner reference |
Placement Rules (in placement/placement_rules/ and placement/placement_rules/template_rules/)
| Class | Location | Purpose |
|-|-|******|
| PlacementRule | placement/placement_rules/ | Base class for all placement rules |
| TileCheckRule | placement/placement_rules/ | Base class for rules evaluating tile/indicator state |
| CollisionsCheckRule | placement/placement_rules/template_rules/ | Checks for overlapping physics bodies |
| WithinTilemapBoundsRule | placement/placement_rules/template_rules/ | Validates placement within tilemap bounds |
| ValidPlacementTileRule | placement/placement_rules/template_rules/ | Basic placement validity check |
| SpendMaterialsRuleGeneric | placement/placement_rules/template_rules/ | Consumes inventory/materials after successful placement |
Runtime Boundary
- Godot nodes + scripts
- Own most runtime behavior.
- Expose the practical runtime API through exports, methods, and shared state objects.
- Composition container + injector
- Wire contexts, states, logger, actions, templates, and settings into nodes.
- State-first coordination
- Many listeners consume shared state directly instead of receiving small isolated payload objects.
High-Level Shape
| |
Data Flow
- Initialization
GBInjectorSystemreadscomposition_container.- It injects any node with
resolve_gb_dependencies(...).
- Scene context application
GBLevelContextappliestarget_map,maps, andobjects_parent.GBOwnerapplies the active owner.
- Input and targeting
GridPositioner2Dprocesses mouse/keyboard input and moves to tile centers.TargetingShapeCast2DupdatesGridTargetingState.target.
- Placement start
- UI or game code calls
BuildingSystem.enter_build_mode(placeable). - Preview/rules/setup are created from the selected
Placeable.
- UI or game code calls
- Validation and commit
- Base rules from
GBSettings.placement_rulesand placeable-specific rules are evaluated. BuildingSystem.try_build()commits placement if validation succeeds.
- Base rules from
- Manipulation
ManipulationSystemmanages move/manipulation workflow.ManipulationParentowns the visual rotation/flip parent hierarchy.
What Plugin Users Should Rely On
- Inspector-driven setup for level wiring and settings.
- Method-based DI via
resolve_gb_dependencies(...). - State-based coordination through
GBStatesandGBContexts. - System entry points such as
enter_build_mode(...),try_build(), and manipulation APIs.
Essential Integration Invariant
The plugin is only fully ready after all of these are true:
GBInjectorSystem.composition_containeris assigned.GBLevelContextis in the scene withtarget_map,maps, andobjects_parentassigned.GBOwneris in the scene withowner_rootassigned.- Systems (BuildingSystem, GridTargetingSystem, ManipulationSystem) are registered via
GBSystemsContext.set_system(). IndicatorContext.indicator_manageris assigned if using indicators.- Runtime validation passes once your level and owner context are actually available.