Slot Rules¶
Slot Rules allow you to restrict what items can be placed into specific inventory slots. This is essential for equipment systems (e.g., ensuring a helmet can only go in the head slot). In v2.0, rules also support dynamic stacking limits.
SlotDefinition (Resource)¶
Every slot in an Inventory has a corresponding SlotDefinition.
- display_name: Name of the slot (e.g., "Head", "Weapon").
- icon_placeholder: Texture shown when the slot is empty.
- rules: An Array[SlotRule] that must all pass for an item to be accepted.
- allow_drag_out / allow_right_click: UI interaction restrictions.
Base Class: SlotRule (Resource)¶
All rules extend SlotRule. In v2.0, rules can now dictate not just if an item can be placed, but how many can be placed.
# Returns true if the item is allowed in this slot.
# 'amount' is the number of items being dropped/added.
func can_accept_item(item: ItemDefinition, slot_index: int, inventory: Inventory, amount: int = 1) -> bool
# Returns the maximum number of items allowed in this slot (overrides item.max_stack_size).
# Return -1 to use the item's default max_stack_size.
func get_max_allowed_amount(item: ItemDefinition, current_count: int, inventory: Inventory) -> int
# Returns a human-readable string explaining why the item was rejected.
func get_rejection_reason(item: ItemDefinition, slot_index: int) -> String
# Returns the color to flash on the slot UI when a drop is invalid.
func get_invalid_drop_feedback() -> Color
Built-in Rules¶
EquipmentTypeRule¶
Locks a slot to a specific integer equipment_type.
- Property:
equipment_type(int). - Usage: Set the rule's
equipment_typeto1. Set your Helmet item'sequipment_typeto1.
ItemTagRule¶
Requires items to have specific string tags.
- Properties:
required_tags(Array[String]),match_any(bool). - Usage: If
match_anyis true, the item needs at least one of the tags. If false, it must have all of them.
MaxOneRule¶
Prevents items from stacking in a specific slot (e.g., equipment slots). - Usage: Add this to equipment slots so players can't stack 64 Iron Swords in a single weapon slot.
Dynamic Limits in v2.0
MaxOneRule now implements get_max_allowed_amount() to return 1. This means even if you drag a stack of 64 swords onto an equipment slot, the system will only allow 1.