GBInjectorSystem
Summary
Section titled “Summary”Dependency injection system for the Grid Building Plugin.
This system automatically handles: 1. Dependency Injection: Wires the GBCompositionContainer
into all nodes that implement resolve_gb_dependencies(p_config: GBCompositionContainer)
2. Automatic Validation: Validates the complete setup after injection and reports any configuration issues via the container’s logger
No manual validation calls are required - the injector handles everything automatically after dependency injection is complete.
The injector operates on a scoped portion of the scene tree (or the whole tree when no injection_roots
are provided). It does not own the composition container — it holds a reference to one and performs injection and validation.
Setup Requirements:
- Assign a
GBCompositionContainer
resource to this injector - EnsureGBLevelContext
andGBOwner
are properly configured before the injector runs (usually in_ready()
methods) - The injector will automatically validate after injection and log any issues
Usage Example:
# In your scene node:func resolve_gb_dependencies(p_config: GBCompositionContainer) -> void: _composition_container = p_config _logger = p_config.get_logger() # No validation call needed - injector handles it automatically
Nodes that implement resolve_gb_dependencies(p_config: GBCompositionContainer)
will be injected automatically by this system.[/i]
Signals
Section titled “Signals”signal initial_injection_completed( )
Emits when the initial scene injection is completed
signal node_injected( node: Node )
Emit whenever a node is injected
Properties
Section titled “Properties”composition_container: GBCompositionContainer
Container services as the single source of truth for settings within it’s scope for systems and other nodes concerned with grid building operations.
Dependencies are injected out of this container by the GBInjectorSystem
injection_roots: Array[Node] = []
Debug settings for logging and warnings. :::note[Note] runtime validation is intentionally NOT auto-run on
_ready()
because other game-level dependencies (GB level context, GBOwner, etc.) may not be fully settled. Callrun_validation()
from your world/initializer script after those dependencies are created and injected. :::Root nodes for injection. These nodes and any children node added will be injected by the GBInjectorSystem. Use this for scoping injection. If left empty, all nodes in the scene tree will be injected.
Methods
Section titled “Methods”func _init( p_composition_container: GBCompositionContainer )
func _ready( )
func _initialize( )
func get_injection_roots( ) -> Array[Node]
Gets the scoped root nodes for injection
func validate_runtime( ) -> bool
Validates the runtime level setup for the grid building system.
Notes: - The authoritative validation is performed by
composition_container.get_runtime_issues()
; this method aggregates container-level issues and any injector-specific checks. - This function does NOT auto-run during_ready()
; callrun_validation()
or call into the container from host code after the composition container has been injected andGBLevelContext
/GBOwner
are available.func run_validation( ) -> bool
Public helper: run validation and return boolean result. Logs issues using the container logger. Public helper: run validation and return boolean result. Logs issues using the container logger. Prefer calling
composition_container.get_runtime_issues()
directly from host scripts when you want to inspect the issue list without logging side-effects.func get_editor_issues( ) -> Array[String]
func get_runtime_issues( ) -> Array[String]
func _inject_existing( p_node: Node ) -> void
func _on_node_added_to_scope( p_scope: Node, p_node: Node ) -> void
Handler for new nodes added to the injection scope.
p_scope
: The scope node to which the new child belongs.p_node
: The newly added child node.static func create_with_injection( p_parent: Node, container: GBCompositionContainer ) -> GBInjectorSystem
Creates a GBInjectorSystem with dependency injection from container.
func resolve_gb_dependencies( p_config: GBCompositionContainer ) -> void
Default resolve hook used by the injector when injecting this system into the scene. Host projects may implement their own
resolve_gb_dependencies
on world or player scripts to capture the container pointer and to run validation. The default implementation here only captures a logger and prints a small diagnostic.func inject_node( p_node: Node ) -> bool
Injects dependencies into a single node (not recursive). Also connects signals to monitor future children and node exiting.
func inject_recursive( p_node: Node ) -> void
Injects dependencies into the node and all its children recursively. Used only on startup to cover existing tree nodes.
func set_injection_meta( p_node: Node ) -> void
Sets the meta data on the object following a successful injection.
func remove_injection_meta( p_node: Node ) -> void
Removes the injection meta data from the object.
func _on_child_entered_tree( p_node: Node ) -> void
Handler for new nodes entering the tree at runtime. Injects only the single node; child nodes will trigger their own injections.
func _on_node_exiting_tree( p_node: Node ) -> void
Handler for node exiting tree to clean up signal connections
func _connect_child_entered_tree( p_node: Node ) -> void
Cleanup injected metadata
Private helper: Connect child_entered_tree signal if not already connected.
func _disconnect_child_entered_tree( p_node: Node ) -> void
Private helper: Disconnect child_entered_tree signal if connected.
func _connect_tree_exiting( p_node: Node ) -> void
Private helper: Connect tree_exiting signal if not already connected.
func _disconnect_tree_exiting( p_node: Node ) -> void
Private helper: Disconnect tree_exiting signal if connected.
func _connect_scene_tree_node_added( ) -> void
func _on_scene_tree_node_added( p_node: Node ) -> void
func _validate_after_injection( ) -> void
Automatically validates the Grid Building setup after injection completes. This is called deferred after initial_injection_completed to ensure all nodes are properly injected and GBLevelContext/GBOwner are configured.
func _report_warning( message: String ) -> void
Private helper: Report warnings through direct print or push_warning.
Source
Section titled “Source”addons/grid_building/systems/injection/gb_injector_system.gd
This API reference is automatically generated from the plugin source code. For implementation examples and usage guides, see the guides section.