CollisionTestSetup
Summary
Section titled “Summary”CollisionTestSetup
Builds collision test parameters for a CollisionObject2D to enable placement indicators to perform accurate collision checks against object geometry.
Purpose: Converts CollisionObject2D shapes into testable RectCollisionTestingSetup instances for collision validation during placement operations.
Key Features: • Creates one RectCollisionTestingSetup per shape owner • Expands test areas using configurable shape_stretch_size • Supports CollisionShape2D and CollisionPolygon2D nodes • Comprehensive error reporting via issues array
Quick Start:
var test_setup = CollisionTestSetup.new(collision_object, Vector2(16, 16), owning_node)if test_setup.validate_setup(): # Use test_setup.rect_collision_test_setups for collision testing pass
Advanced Documentation: For detailed usage, API reference, and troubleshooting, see: https://gridbuilding.pages.dev/api/v5.0.0/CollisionTestSetup
Dependencies: RectCollisionTestingSetup, GBGeometryUtils
Properties
Section titled “Properties”collision_object: CollisionObject2D :
The CollisionObject2D being analyzed for collision testing.
owning_node: Node2D
The owning Node2D that contains this collision object (e.g., the test object or scene node). This provides context about which object this collision setup belongs to.
shape_stretch_size: Vector2
Size to stretch collision shapes for comprehensive tile coverage. Recommended: Use your tile size (e.g., Vector2(16, 16) for 16x16 tiles). See advanced documentation for detailed sizing guidance.
rect_collision_test_setups: Array[RectCollisionTestingSetup]
Array of RectCollisionTestingSetup instances, one per shape owner. Use these setups to perform collision tests for placement indicators.
issues: Array[String] = []
Issues discovered during collision test setup. Check this array after initialization to identify configuration problems.
Methods
Section titled “Methods”func _init( p_collision_object: CollisionObject2D, p_shape_stretch_size: Vector2, p_owning_node: Node2D ) -> void
Initializes collision test setup for the given CollisionObject2D.
func add_issue( p_issue: String ) -> void
Records an issue encountered during setup.
func free_testing_nodes( ) -> void
Frees all testing nodes created during setup. Call this when the setup is no longer needed to prevent memory leaks.
func validate_setup( ) -> bool
Validates the collision test setup and reports any issues. Returns true if setup is valid and ready for use, false otherwise.
func _create_rect_tests_for_collision_object( p_collision_object: CollisionObject2D ) -> Array[RectCollisionTestingSetup]
Creates RectCollisionTestingSetup instances for each shape owner in the CollisionObject2D.
func _get_testing_rect_for_owner( p_shape_owner: Node2D ) -> Rect2
Calculates the testing rectangle for a shape owner node. Supports CollisionShape2D and CollisionPolygon2D nodes.
func _adjust_rect_to_testing_size( p_base_rect: Rect2, p_shape_owner_global_transform: Transform2D ) -> Rect2
Expands the rectangle by shape_stretch_size to ensure comprehensive tile coverage. Handles complex transforms by converting to squares when rotation/skew is present.
Source
Section titled “Source”addons/grid_building/placement/collsion_test/collision_test_setup.gd
This API reference is automatically generated from the plugin source code. For implementation examples and usage guides, see the guides section.