Item Logic¶
ItemLogic allows you to attach custom, scriptable behaviors to items. Instead of writing massive match statements in your player controller, you assign a Logic script to an ItemDefinition.
Automatic Execution via EquipmentManager
You do not need to write code in your player controller to trigger item logic!
Simply add an EquipmentManager node to your player, assign your ModularHotbar, and it will automatically detect input and call on_primary_use(), on_release(), and update() on the active item.
Base Class: ItemLogic (RefCounted)¶
All custom logic scripts must extend ItemLogic.
Setup & Teardown¶
# Called when the logic is initialized. v2.0 provides full context!
func setup(item: ItemDefinition, player: Node, slot_index: int = -1, weapon_model: Node3D = null, inventory: Inventory = null) -> void
# Called when the item is unequipped or the slot changes. Free custom nodes here!
func cleanup() -> void
Execution Methods¶
# Return false to prevent the item from being used (e.g., out of stamina).
func can_use() -> bool
# Called when the player presses the "Primary Use" button (e.g., Left Click).
func on_primary_use(slot_index: int = -1) -> void
# Called when the player presses the "Secondary Use" button (e.g., Right Click).
func on_secondary_use(slot_index: int = -1) -> void
# Called when the player releases the "Use" button (great for charged attacks).
func on_release() -> void
# Called every frame while the item is being held/used.
func update(delta: float) -> void
# Direct access to raw input events (handled by EquipmentManager).
func on_input(event: InputEvent) -> void
Signals¶
use_started: Emitted when use begins.use_ended: Emitted when use finishes.use_finished(item: ItemDefinition, success: bool): Emitted with the final result.