Save Inventory Not Working

Trying to create a save inventory function. But, it isnt working. It generates the save file, but inventory doesnt save, and does not load, any advice would be helpful

SaveInventory

Load Inventory

Event Graph

Hey,

How do you have your Save Game object setup? Is it via BP or C++?

If this is C++ make sure the properties you are saving are marked as UPROPERTY.

Its by blueprint

I fixed the initial issue, but now, it is saving the player inventory across containers.

What do you mean across containers? Like you want to have multiple save files and its overwriting them?

No no, so, if I have a chest, when the inventory saves, and I go back in, it did save my inventory, but what was in my inventory is now also int he chest.

That sounds like potentially an issue with the chest. Where does the chest pull the data from? Alternatively is it the UI and not the chest? Maybve Print the content of the chest when opened to confirm

I think its because the guy I am following the tutrial of, uses the same FSlot_Struct for both player and container inventory. So Any time anything references/gets/stores anything with the “Content” variable/array, and its all built on Fslot_Struct, its saving to ALL inventories because they are not separate.

Chest is just a mesh with a name, all inventory display events are handled by UI elements/displays. But they are also pulling from the content built on Fslot_Struct.

When you say the same Struct do you mean the same instance of the Struct or just the same type? If they are using the same Inventory then yes this would explain the issue here.

If you have the tutorial link Im happy to take a look and see where the issue might be

I think that is the case, but here is the link to the playlist. They are mostly titled appropriately. But should be able to tell within the first video or two.

Inventory Creation Tutorial - Ryan Laley

Okay yeah just looking through those now.

To confirm the Inventory looks correct the first time you open the chest, its only after Loading from the Save Game that this is displayed incorrectly?

As soon as I implemented the save inventory function, the chest stopped spawning its contents, and replaced it with a copy of the player inventory.

Ah yeah I think I see the issue, the LoadInventory on begin play of the InventorySystem component is always loading the Player Inventory. There needs to be some sort of check there to either skip that for non Players. This is because the Container and the Player use the same Component type here.

Ideally, I would recommend creating a child class from the InventorySystem for Players specifically that implements the save Logic.

Yeah I was thinking that, create a separate one for chests etc. Id redo one for player, but theres so much work into it already, seeing as theres only one container in the world right now making one for the containers might be easier lol

Just create a child name it something else and have containers use the child version.

Yeah so Id probably create the Player version as the Child as its going to be the more complex one. Your going to want the simple stuff in the base and then things like Loading Saving etc can just go in the Child Class specifically for the Player.

I believe that is the issue though for now you could jsut test with a bool that you set to false on the Container and thats used to check whether to Load/Save.

Fair enough, means id have to clear out everything from the parent though otherwise itll have duplication issues.

Yeah for now you could just add the Bool to gate it for everything other than the Player if thats easier.

I have no idea how to do that. Still pretty new to all this xD

No worries, so if you create a new Bool property on the InventorySystem component, named something like bShouldSave and default this to False. Then in your Component whenever you run Load or Save add a Branch at the beginning of this and only run the Load/Save if that boolean is True.

Then on the Component in your Character set this to be True (Similar to how you set Quantity on the Item Component).

So the bShouldSave would be the condition of the branch. But how would it tell the inv to load if its a person, and not load if it s chest?