Skip to content

SpendMaterialsRuleGeneric

Generic material spending rule for placement validation.

Allows custom resource classes without building system inventory dependencies. Expects resource stacks with type and count properties. Looks for _mat_container on the target building node.

Required inventory methods:

try_add or add - Parameters: type: Resource, count: int

try_remove or remove - Parameters: type: Resource, count: int

get_count - Parameters: type: Resource - Returns: int

Alternative: inherit from VirtualItemContainer and implement the methods.

resource_stacks_to_spend: Array[ResourceStack] = []

How many of each type need to be spent for the building rule to pass Resource should have fields type and count defined

locator: NodeLocator

Used to find the inventory on the _spender passed in as a setup parameter so that the rule knows where to spend the resource_stacks_to_spend from

success_reason: String = “Can afford”

Player-friendly reason shown when materials are available

failure_reason: String = “Not enough resources”

Player-friendly reason shown when materials are missing

setup( p_gts: GridTargetingState ) -> Array[String]
apply( ) -> Array[String]

Tries to spend the resources from the _mat_container Returns an array of issues found during the spending process If the spending was successful, the array will be empty

tear_down( )
validate_placement( ) -> RuleResult

Checks to see if there are enough resources to build item

check_missing_resources( p_spender_container ) -> Array[ResourceStack]

Checks the resouce _mat_container to see if it has enough of each resource type Returns ItemStacks that contain the amount missing for each type

addons/grid_building/placement/placement_rules/template_rules/spend_materials_rule_generic.gd


This page was auto-generated from GDScript source. Edit the source file to improve documentation.

Generated on 2025-09-07