GridTargetingSystem
Summary
Section titled “Summary”Tracks mouse position on the target map with tile snapping.
Converts screen coordinates to grid coordinates and manages grid-based targeting for placement and manipulation systems.
Signals
Section titled “Signals”signal astar_grid_changed( astar_grid: AStarGrid2D )
Emitted when the AStarGrid2D used by the Grid Targeting System is created or changes
Properties
Section titled “Properties”target_tile: Vector2
The tile location where the mouse is currently hovering over represented as X / Y values of the _targeting_state.target_map
mouse_handled: bool = false
Whether the mouse input was consumed by GUI already or not
astar_grid = AStarGrid2D.new()
Pathfinding for a 2d Tile Grid through the AStar search algorithm
Methods
Section titled “Methods”get_runtime_issues( ) -> Array[String]
Validates that all required dependencies are properly set. Returns list of validation issues (empty if valid).
get_state( ) -> GridTargetingState
Compatibility accessor for older tests expecting get_state(). Returns the underlying GridTargetingState used by this system.
_process( delta: float ) -> void
Continuous positioner updates on _process() instead of only on mouse movement
resolve_gb_dependencies( p_container: GBCompositionContainer ) -> void
move_node_to_closest_valid_tile( p_target_tile: Vector2i, p_positioner: Node2D, p_source: Node2D ) -> Error
Move the positioner to adjust the shown position of any visual _targeting_settings elements. If limit_to_adjacent setting is on, the closest valid target will be limited by the p_source position and the max_tiles_distance.
p_target_tile
: Vector2i - Desired tile location to move top_positioner
: Node2D - Node to move to the target positionp_source
: Node2D - Source node for distance calculations when limit_to_adjacent is enabledmove_to_tile( p_node: Node2D, p_tile: Vector2 ) -> Error
Adjust by p_tile_map position to get global position
Moves a target node to the center snapped position of a p_tile on the _targeting_state.target_map.
p_node
: Node2D - Node to move to the tile positionp_tile
: Vector2 - Tile coordinates to move toget_tile_from_global_position( p_global_position: Vector2, p_map: Node2D )
Returns the tile on the p_tile_map where the mouse is currently hovering over.
p_global_position
: Vector2 - Global position to convert to tile coordinatesp_map
: Node2D - TileMap or TileMapLayer to use for coordinate conversionget_max_tile_distance_tile_to_target( p_node: Node2D, p_target_tile: Vector2i )
Given a target tile, finds the tile that is the closest to the target that does not go above the max tile distance from the p_node Node2D. Returns valid tile Vector2i or null if none available.
p_node
: Node2D - Source node for distance calculationsp_target_tile
: Vector2i - Target tile to find closest valid tile toupdate_astar_grid_2d( p_astar: AStarGrid2D, p_targeting_settings: GridTargetingSettings )
Updates an AStarGrid2D according to a set of GridTargetingSettings.
p_astar
: AStarGrid2D - AStar grid to configurep_targeting_settings
: GridTargetingSettings - Settings to apply to the AStar gridsnap_tile_to_region( p_tile: Vector2i, p_region: Rect2i ) -> Vector2i
Give a tile position Vector2i, returns the closest point in the rect2i.
p_tile
: Vector2i - Tile position to snap to region boundsp_region
: Rect2i - Rectangle region to snap the tile position withinvalidate_and_log_issues( ) -> Array[String]
Public manual validation entry point for host projects. Runs get_runtime_issues() and logs issues without relying on timed warnings. Returns the list of issues (empty when valid).
validate_ready( ) -> bool
For tests we expect the system to be inside the scene tree already.
get_targeting_issues( ) -> Array[String]
Gets issues that would prevent the targeting_system from being able to target. This should be called after grid targeting state properties have all been defined
Source
Section titled “Source”addons/grid_building/systems/grid_targeting/grid_targeting_system.gd
This page was auto-generated from GDScript source. Edit the source file to improve documentation.
Generated on 2025-09-07