Storage Chest Inventory Management

Godot Version

v4.4 stable.official.4c311cb11

Question

What is the best way to manage unique inventory between multiple storage chests, using data resources?

First of all, I am using Michael Games’ “Make a 2D Action & Adventure RPG in Godot 4” YouTube tutorials for my base game architecture. Great tutorials by the way. My code is a heavily modified version of this. I have implemented a click based movable inventory system like Stardew Valley uses (click an item in the inventory then click another item or empty space and it will either place the item or swap). I like the feeling of this over drag-n-drop.

I have come to the point of starting storage chests and would like some input from others. I am not finding much info out there that relates to my setup. I’ll try my best to explain my setup.

-My Layout
My player inventory is player_inventory.tres , which is an InventoryData Resource, consisting of SlotData(slot info). This was created by right clicking the folder, create new resource, then selecting InventoryData. All of my code for adding, removing, sorting, etc. of items is in the InventoryData script. The inventory slots also transfer signals (func _on_gui_input) thru this script for mouse button action (left/right click).

I then have a grid container with a script that controls the UI aspect of the inventory. It populates given the content of player_inventory.tres.

-Chest Creation
When creating the storage chest, I can create a new resource using InventoryData to store the items in, storage_inventory.tres for example. It works great except all my storage chests have the same inventory because they all look back to this same storage_inventory.tres resource file. Is there a way to instantiate this or am I looking at this all wrong?

I have also created a chest with an array of SlotData to use in place of the InventoryData resource, which allows each chest to have its own unique inventory. This option, however disables my ability to get the left/right click signals from my inventory slots, which is needed.

Thanks in advance for feedback!

You are pretty much there. You don’t need to save to disk the chest inventory, just create a new built-in InventoryData resource for each chest with the contents of the chest.

Check the documentation page about resources Resources — Godot Engine (stable) documentation in English for a deeper explanation about them.

2 Likes

Thanks mrcdk for the advice. I have incorporated a new InventoryData using documentation and Google AI search. Instead of the original InventoryData, I create a StorageInventoryData with less complex code, due to the players inventory being sliced to include equipment slots.

I appear to have the slots populating the storage inventory but cannot test the items, as I have a break in my left/right click signals. My signals reach the StorageInventoryData from the inventory slot but it is not making it to the next script that handles the UI within the storage chest.

Hold tight and I will debug some more.

Edit: I had the signals connecting before I sent the inventory data from the chest to the UI.
Now when I go between storage chests, the items do nothing when clicked. There must me a connection issue where it is not reconnecting when I open the storage.

Without any code is hard to tell where the issue is.

1 Like

I got it. I was calling my signal connections at the wrong time.