Grid Placement

CollisionsCheckRule

AUTO-GENERATED FILE — DO NOT EDIT MANUALLY

Source: systems/placement/validators/placement_rules/template_rules/collisions_check_rule.gd

Version: 5.1

class_name: CollisionsCheckRule extends: TileCheckRule

Summary

Rule that validates placement based on collision detection.

This rule checks for physics collisions at indicator positions and validates based on the [member pass_on_collision] setting:

  • [code]false[/code] (default): Placement FAILS if collision detected (“must have clear space”)
  • [code]true[/code]: Placement FAILS if NO collision detected (“must overlap with existing objects”)

Signals

(none)

Exports

  • pass_on_collision
    • Controls collision validation behavior:
  • [code]false[/code]: Rule PASSES when no collision (placement requires clear space)
  • [code]true[/code]: Rule PASSES when collision detected (placement requires overlap)

Common use cases:

  • [code]false[/code]: Building placement (needs empty space)
  • [code]true[/code]: Attachment mechanics (must connect to existing structures)
  • messages
    • Modular message configuration resource

Methods

  • _init()
  • setup()
    • Setup the rule with the provided PlacementRuleContext. Returns an array of issues found during setup. [code]p_context[/code]: [i]PlacementRuleContext[/i] - Data-only validation context [returns] Array[String] - Array of issues found during setup
  • validate_placement()
    • Validates placement by checking collisions on all provided indicators. Returns a RuleResult with success/failure and messages.
  • get_failing_indicators()
    • Runs the rule against an array of indicators. Returns the number of failing indicators.[br][br] [code]p_indicators[/code]: [i]Array[RuleCheckIndicator][/i] - Array of indicators to test collision against [code]p_context[/code]: [i]PlacementRuleContext[/i] - Data-only validation context NOTE: This method is public and should be used directly by callers. The previous private wrapper _get_failing_indicators was removed to simplify the API.
  • _apply_collision_exclusions_to_indicators()
    • Apply collision exclusions to all indicators before validation. This ensures exclusions are consistently applied regardless of validation entry point. Uses both collision layer manipulation AND ShapeCast2D exceptions for maximum reliability.
  • _apply_collision_layer_exclusions()
    • Apply collision layer manipulation for excluded objects. This is more reliable than ShapeCast2D exceptions which have timing issues.
  • _store_and_clear_collision_layers_recursive()
    • Store original collision layers and clear them for a node and its children
  • _restore_collision_layer_exclusions()
    • Restore original collision layers for all excluded objects
  • _indicator_apply_collision_exclusion_exceptions()
    • Add collision exclusion exceptions on the shape cast. This provides immediate exclusion behavior alongside collision layer manipulation.
  • _indicator_apply_preview_target_exceptions()
    • Add only preview target exceptions on the shape cast. Collision exclusions are handled via layer manipulation instead.
  • _collect_bodies_recursive()
  • _cleanup_collision_exclusions()
    • Called when targeting state changes - ensures cleanup happens at the right time Cleanup method to ensure collision layers are restored
  • get_editor_issues()
    • Returns an array of issues found during editor validation
  • get_runtime_issues()
    • Returns an array of issues found during runtime validation