Composition Container Configuration (v5.0)
The GBCompositionContainer is the central configuration hub for GridBuilding v5.0, organizing all sub-resources and providing dependency injection for the building system.
For a complete setup overview, see Getting Started Setup.
Overview
The composition container follows a hierarchical resource structure where each sub-resource controls a specific aspect of the building system. This design allows for modular configuration and live updates without system restarts.
Resource Hierarchy
GBCompositionContainer (Resource)
├── config: GBConfig
│ ├── settings: GBSettings
│ │ ├── building: BuildingSettings
│ │ ├── manipulation: ManipulationSettings
│ │ ├── targeting: GridTargetingSettings
│ │ ├── visual: GBVisualSettings
│ │ ├── action_log: ActionLogSettings
│ │ ├── placement_rules: Array[PlacementRule]
│ │ ├── runtime_checks: GBRuntimeChecks
│ │ └── debug: GBDebugSettings
│ ├── templates: GBTemplates
│ └── actions: GBActions
Creating Resources (Editor-Based Approach)
Important: For v5.0, resource assignment must be done manually in the Godot Editor Inspector. There is no automatic assignment of resources. You must manually create and assign each sub-resource. Save frequently to prevent data loss.
Step 1: Base Container (Editor)
- In the Inspector, click “Create New Resource”
- Search for and select
GBCompositionContainer - Save immediately as
composition_container.tresto prevent data loss - Assign this resource to your
InjectorSystem’scomposition_containerproperty
Step 2: Main Config (Editor)
- Click the
configproperty in your composition container - Select “Create New Resource” →
GBConfig - Save immediately as
config.tresto prevent data loss - The config is manually assigned to the container
Step 3: Settings Container (Editor)
- Click the
settingsproperty in your config resource - Select “Create New Resource” →
GBSettings - Save immediately as
settings.tresto prevent data loss - The settings are manually assigned to the config
Step 4: Individual Settings (Manual Assignment Required)
Important: Each individual setting resource must be manually created and assigned:
Building Settings:
- Click
buildingproperty in GBSettings - Select “Create New Resource” →
BuildingSettings - Save immediately as
building_settings.tres
- Click
Manipulation Settings:
- Click
manipulationproperty in GBSettings - Select “Create New Resource” →
ManipulationSettings - Save immediately as
manipulation_settings.tres
- Click
Targeting Settings:
- Click
targetingproperty in GBSettings - Select “Create New Resource” →
GridTargetingSettings - Save immediately as
targeting_settings.tres
- Click
Visual Settings:
- Click
visualproperty in GBSettings - Select “Create New Resource” →
GBVisualSettings - Save immediately as
visual_settings.tres
- Click
Templates:
- Click
templatesproperty in GBConfig - Select “Create New Resource” →
GBTemplates - Save immediately as
templates.tres
- Click
Actions:
- Click
actionsproperty in GBConfig - Select “Create New Resource” →
GBActions - Save immediately as
actions.tres
- Click
Critical: Save each resource immediately after creation to prevent data loss if Godot crashes or the project is closed unexpectedly.
Why Editor-Based Assignment?
- Visual Validation: The Inspector shows missing properties and validation errors
- Type Safety: Godot ensures correct resource types are assigned
- Live Updates: Changes propagate immediately to all systems
- Debugging: Easy to inspect resource contents during development
- Performance: No runtime loading overhead
Script-Based Assignment (Advanced Only)
| |
Individual Settings Configuration
BuildingSettings
Controls core building and placement behavior:
| |
Key Properties:
grid_size: Size of building grid cellsplacement_validation: Enable/disable placement checkscost_requirements: Resource costs for buildingbuilding_rules: Custom building logic rules
ManipulationSettings
Controls object movement and editing:
| |
Key Properties:
drag_sensitivity: Mouse drag sensitivitysnap_to_grid: Force grid snapping during manipulationmanipulation_modes: Available editing modes
GridTargetingSettings
Controls grid targeting and selection:
| |
Key Properties:
target_range: Maximum targeting distanceselection_shape: Shape for target detectioncollision_layers: Physics layers for targetingtarget_highlight_color: Visual feedback color
GBVisualSettings
Controls UI and visual feedback:
| |
Key Properties:
cursor_style: Custom cursor texturehighlight_color: Selection highlight colorshow_target_info: Display target informationui_scale: UI element scaling
ActionLogSettings
Controls logging system behavior:
| |
Key Properties:
max_messages: Maximum logged messagesmessage_duration: How long messages displaylog_level: Minimum log severityshow_timestamps: Include time information
Placement Rules
Array of validation rules for placement:
| |
Common Rule Types:
- Terrain validation
- Cost requirements
- Space availability
- Custom game logic
GBRuntimeChecks
Controls system validation and debugging:
| |
GBDebugSettings
Development and debugging configuration:
| |
Templates Configuration
GBTemplates
Define system and UI templates:
| |
Actions Configuration
GBActions
Define input mappings:
| |
Resource Assignment Pattern
Critical: There is NO automatic assignment of resources. You must manually assign each sub-resource:
- Open your composition container resource in the Inspector
- For each property field (config, settings, building, manipulation, targeting, visual, templates, actions):
- Click the property field
- Select “Create New Resource” or “Load Resource”
- Save immediately after creating each resource
- Repeat for all nested properties - each must be manually assigned
Visual Validation: The Inspector will show:
- ✅ Green checkmarks for properly assigned resources
- ❌ Red indicators for missing or invalid resources
- ⚠️ Warnings for configuration issues
Save Strategy:
- Save each resource immediately after creation
- Use descriptive names (e.g.,
building_settings.tres,manipulation_settings.tres) - Keep all resources in a dedicated
settings/folder - Commit to version control frequently
Folder Structure
Use a consistent folder structure for organization:
res://settings/
├── composition_container.tres
├── config.tres
├── settings.tres
├── building/
│ ├── building_settings.tres
│ └── building_rules/
├── manipulation/
│ └── manipulation_settings.tres
├── targeting/
│ └── targeting_settings.tres
├── visual/
│ └── visual_settings.tres
├── templates/
│ └── templates.tres
└── actions/
└── actions.tres
Script-Based Assignment (Advanced Only)
| |
When to Use Script-Based Assignment:
- Multi-environment configurations (dev/staging/prod)
- User-configurable settings
- Mod support with custom configurations
- A/B testing different configurations
Risks of Script-Based Assignment:
- No editor validation
- Runtime errors if resources are missing
- Harder to debug configuration issues
- Performance overhead from runtime loading
Shared Resource Behavior
All settings resources are shared Godot Resources with these properties:
- Live Updates: Changes propagate immediately to all systems
- Reference Sharing: Multiple systems can reference the same resource
- Scene Local: Use
resource_local_to_scene = truefor per-scene instances
Example Live Update
| |
Validation
The composition container provides automatic validation:
Editor Validation
- Checks for missing required resources
- Validates resource types and properties
- Reports configuration issues in the Inspector
Runtime Validation
- Verifies system dependencies
- Checks runtime state consistency
- Provides detailed error reporting
| |
Best Practices
1. Modular Organization
- Keep individual settings in separate files
- Use descriptive naming conventions
- Group related settings together
2. Version Control
- Commit resource files alongside code
- Use meaningful commit messages for setting changes
- Document breaking changes in settings
3. Performance Considerations
- Avoid heavy computations in setting getters
- Cache expensive calculations
- Use lazy initialization where appropriate
4. Testing
- Create test configurations for different scenarios
- Validate settings with automated tests
- Test live updates during gameplay
Common Configuration Patterns
Minimal Setup
| |
Production Setup
| |
Multi-Environment Setup
| |
Troubleshooting
Common Issues
- Missing Resources: Ensure all sub-resources are properly assigned
- Invalid References: Check that all resource paths are valid
- Type Mismatches: Verify resource types match expected classes
- Circular Dependencies: Avoid circular references between resources
- Data Loss: Resources not saved when Godot crashes or closes unexpectedly
Data Loss Prevention
Critical Issues:
- Resources created but not saved before Godot crash
- Manual assignment errors causing resource loss
- Version control not committing resource files
Prevention Strategies:
| |
Recovery Steps:
- Check Godot’s
autosave/folder for recent backups - Look in your project’s
.godot/directory for cached resources - Restore from version control if available
- Recreate missing resources using the detailed setup guide
Manual Assignment Verification
Checklist for Complete Setup:
- GBCompositionContainer created and saved
- GBConfig created, assigned, and saved
- GBSettings created, assigned, and saved
- BuildingSettings created, assigned, and saved
- ManipulationSettings created, assigned, and saved
- GridTargetingSettings created, assigned, and saved
- GBVisualSettings created, assigned, and saved
- GBTemplates created, assigned, and saved
- GBActions created, assigned, and saved
- All resources committed to version control
Debug Tools
- Use
get_runtime_issues()to identify problems - Enable debug settings for detailed logging
- Check the Inspector for validation warnings
Integration with Systems
The composition container automatically integrates with:
- InjectorSystem: Provides dependency injection
- BuildingSystem: Uses building and placement settings
- ManipulationSystem: Uses manipulation settings
- TargetingSystem: Uses targeting and visual settings
- UI Systems: Use templates and actions
This integration ensures all systems have access to the correct configuration without manual wiring.