Containers & Chests¶
Creating an interactive container (like a chest) in v2.0 is handled entirely by the UIStateManager. You no longer need to manually toggle visibility or manage mouse states.
Step-by-Step Setup¶
1. Physical Container & Inventory¶
- Create a
StaticBody3DorRigidBody3Dfor your chest. - Add an
InventoryComponentas a child. Set the Capacity.
2. Create the Chest UI Scene¶
- Create a new Scene.
- Add a
ModularInventoryPanel(or useSlotGrid+InventoryBinder). - Save this scene.
3. Interaction Logic¶
When the player presses "E", use the UIStateManager to open both the player and chest inventories.
@export var player_ui_scene: PackedScene
@export var chest_ui_scene: PackedScene
@export var player_inv: InventoryComponent
@export var chest_inv: InventoryComponent
func open_chest():
# 1. Open Player Inventory (Role: "player" -> anchors to the right)
UIStateManager.open_panel(
player_ui_scene,
player_inv.inventory,
"Inventory",
"player"
)
# 2. Open Chest Inventory (Role: "container" -> anchors to the left)
UIStateManager.open_panel(
chest_ui_scene,
chest_inv.inventory,
"Chest",
"container"
)
4. Closing the Container¶
To close the container, simply call close_all().
Quick Moving Items
Because both panels are registered with the UIStateManager, players can now Shift+Click items to instantly transfer them between the chest and their inventory!