i can only answer in more abstact ways now as i cant follow all the changes.
to save and load chests.
chests exist in the level so you’d save/load them to the level data
you can get them with GetAllActorsWithInterface like everything else
you may need to expand on the interface, have an enum for what youre saving actor/chest and then switch on enum to return the savedata, ie chest save data struct and actor save data struct.
you can do this for any number of objects you want to save
I’ve tried to do the steps listed, and I’ve come up with 2 problems. In my chest inventory blueprint and in my chest inventory widget, there are two different inventory components. For the data inside the inventory, it seems to be stored in the widget’s inventory component. Because the widgets will only be open one at a time and because they’re widgets, I’m unsure how to access the widgets to save the stored data inside. I’m wondering if I should either change it so the chest actor inventory is the one storing the data, or if I should save the data in the widget, or if there’s another better way. I’ll try to test it out myself as well.
The second problem is that the data inside ONE inventory is an array. So how would I go about saving multiple chest inventories? Is there a way to do an array of arrays, or is there a better solution?
Ok, those issues seem to be cleared up, then. It didn’t seem to change the lack of saving of the chest.
I’m having a really particular issue where if I save a game and load back in, the player inventory displays correctly. If I attempt to move any items to the chest, and then save and exit, when I load back in, the player inventory is gone in all 3 ways it can be opened (chest inventory, with the “I” shortcut, and in the in-game menu), and all items are erased from the world. I have been having a hard time understanding why this is, and it may be related to the lack of saving, although that could be a whole other issue entirely that I haven’t caught yet.
you dont seem to be actually saving or loading the chest at all?
the way to do it is exactly the same as items, save the chest class, transform and add the inventory array. on load destroy them all and spawn then set inventory array.
Because it’s hard to reference, I’ve added the save and load to the Chest Inventory and Chest Object Blueprints. I tried to do as instructed. Now nothing is spawning in, not even the items. I think my thought process through this was quite muddled, but I’ve tried to make it make sense. I’m not sure how to make the UI_ChestInventory read the container index from BP_Chest, I’ve written a note in the UI Chest to clear up what I mean.
just treat it all the same way you save items but with a different struct.
So S_Item is (class,transform)
S_Chest is (class,transform, inventory)
S_NPC is (class, transform, NPCDATA)
etc
on save you get all actors of X (X is item, npc, chest) calls its save function (item, chest, npc) etc
on load you spawn class at transform and set optional data (inventroy/NPCDATA) etc
Previously I had not saved the inventory data component to the chest structure, so I added that and made some adjustments. Now, every now and then, the objects in the scene (excluding the chest) will show up fine on the level, but most of the time nothing shows up on load. I’ve tried to follow these instructions again, here are my updated blueprints.
It doesn’t say spawnActor NONE in my UE blueprint, but it probably means it regardless.
I got it: when a new gamesave is created, I forgot to make it so a new save game object was created to save to when the player saves. That’s why the save data would be empty, and probably why it wouldn’t spawn anything, either. Unfortunately, this change hasn’t effected the functionality, though now the savegameobjects are valid. It’s likely due to the spawnactor not working. Using the is empty node, I found that on load, the actor data and container struct are empty within the save data level. I’m not sure why this would be. In the Save All Data, I clear the structs before adding the items currently in the world into the array, but I’m thinking the second step there doesn’t happen, resulting in an empty array. I checked if the BPI Chest and BPI Item arrays had items in it when I got all actors with interface. The container array has contents inside, which means it should theoretically loop and be added to the container struct/actor data array. But it’s not doing so. The actor data array, however, is empty when I Save All Data. So I’m not sure what this means…
The item loop isn’t empty, but it still doesn’t spawn in. I had it in my head that I had to keep track of the container’s indexs, but I realize that was making things unnecessarily complex.
So I put the inventory system and contents in the container struct, save it, and when it loads, I set both to the chest I spawn, that’ll get the chest data correctly to the chest, right?
Neither are empty anymore, that’s good. And the chest loaded in, but looking like this, and I’m getting the following error;
Blueprint Runtime Error: "Attempted to access ChestInventory via property ChestInventory, but ChestInventory is not valid (pending kill or garbage)". Node: Set ObjectData Graph: Load All Data Function: Load All Data Blueprint: BP_GameInstance
Blueprint Runtime Error: "Attempted to assign to None". Node: Set ObjectData Graph: Load All Data Function: Load All Data Blueprint: BP_GameInstance
I don’t know why that would be. The inventory in the container struct it is drawing from is invalid, I checked through print string, but it’s added to the structure in Find Chest Info directly from the chest inventory, and that IS valid.
So now I’m looking at the Find Chest Info, and even when I put an item in the inventory, the Object Data variable inside of the chest reads as empty. I’m not sure why this is because this is where I recall storing the items inside the inventory. I’m wondering if I should also save the content struct, because it’s reading as NOT empty, though when I load in, the items in the chest do not load (the slots do load, but they are all empty.) I would think I’m saving all the appropriate things at this point, but I suppose I’m not sure.
Today when testing, it looks like both the chest and items around the map are showing up appropriately, so that’s good.
Object Data is an array of F_SaveItemStructs that include the class and transform of objects (which I don’t really know why this would be something I need when looking for data on whats INSIDE the chest. That could very well be the wrong type of struct, and maybe that’s why it isn’t working.)
Content is an array of F_SlotStruct that includes an Item ID and quantity of items in the inventory.
The tutorial also created an ItemStruct, but I don’t think I’m referencing that anywhere in the chest save system. It looks to be the structure that. I think this might be the issue but the confusing part was that the player inventory is functional, and it too uses the SaveItem struct.
So I’ve taken a look at the uses in my blueprints of the SaveItem Struct. In the Inventory Slot, the pre-construct pulls from the ‘content’ structure, using the ID to find the item in the data table (visuals here). So what I’m finding is that Object Data means nothing. Content is the one to focus on. I realized I was forgetting to set the content on load, because I’d been so focused on Object Data. Once I did that, I finally was able to see the contents in the chest inventory. I’ve erased most, if not all, of the Object Data parts of the container part of the save system.
One last problem that I can find. I troubleshooted a bit, and I found why the items and chest would, at “random” times, not spawn in on load. I’m not sure why or how, but it turns out that it only happens whenever the inventory is empty. I’ve attempted to clean up all my blueprints, hopefully that helps. Thank you for your patience and help.
I had followed the tutorial for this part, and the item struct does not have an array inside for the slot struct, but the slot struct is linked to a data table (by itemID, name class)
But after coming back to this a day or so later, I can’t find the error I was talking about here. So I’m hesitant to say, but I think the problems in this thread are cleared up. Thank you so much for helping me out : D