Containers & Chests¶
Creating an interactive container (like a chest or crate) requires linking a 3D physical object with an InventoryComponent and a UI panel.
Step-by-Step Setup¶
1. Physical Container¶
Create a RigidBody3D or StaticBody3D for your chest model.
2. Inventory Data¶
Add an InventoryComponent as a child of the chest.
-
Set the Capacity (e.g., 5 slots for a small pouch, 20 for a large chest).
-
Optional: Assign specific
SlotDefinitions if the chest only accepts certain items.
3. UI¶
Add a ModularInventoryPanel to your main UI CanvasLayer.
-
In the Inspector, link the
source_componentto the chest'sInventoryComponent. -
Ensure the panel is initially set to
visible = false.
4. Interaction Logic¶
You need a way for the player to open the chest. You can use an Area3D or a RayCast3D. When the player presses "E":
func open_chest():
player_ui.visible = true
chest_ui.visible = true
# Automatically arrange them side-by-side
UICoordinator.position_inventory(player_ui, "player")
UICoordinator.position_inventory(chest_ui, "container", player_ui)
InputMode.ui() # Show the mouse cursor
5. Closing the Container¶
When the player presses "E" again or walks away: