How to save an inventory array?

Hi, I’ve followed a tutorial on creating an inventory system, followed it pretty 1 to 1 so my inventory code works effectively the same (https://youtu.be/b2atcZWYi3E?si=ynpmm1xGla5mJQky) and have also already created a working save system in my game. I now want to be able to load/save the stored inventory objects but (being new) can’t seem to figure out how to get it to work. I clasped my hands and prayed it would be as simple as just saving the array, then getting it when loading (screenshots) but expectedly it didn’t work. I couldn’t find anything that would help as I’m not even sure if it’s the saving, the loading, or something in the way the inventory loads the items that is the problem. Help is greatly appreciated.

1 Like

where are you actually saving it though, ie the SaveGameObject and writing/reading from disk?

1 Like

Saving the information to a structure, which is saved/loaded in the game instance

it looks ok from what i can see, although dont forget to call OnLoaded on your non Async path.

so to delve deeper, what error/problem are you getting?

1 Like

I’m not getting any particular errors, the problem is when the game is saved, closed then loaded the items I picked up and had in my inventory aren’t there anymore. The question is quite general as they are stored in an array, and I don’t know how to save and load arrays at all (or even print them for debugging for that matter), so I’m not sure where the problem lies. The youtube video I linked is the inventory tutorial I followed so that may help but I’m not sure. I have to sleep now so I may not respond for a bit.

so what calls LoadGameData?

youre calling a dispatcher OnGameLoaded, but who is listening and do they exist at that point?

do the Casts fail?

Setting an array var from a saved copy like you did should work. I’ve done it before. To debug it, use a foreachloop, break the struct, then print one of the members:

Try that on save function also to make sure it’s actually saving teh array.

Managed to save it due to the help of the debugging blueprint, the issue lied with the loading of the inventory iteself in the widget, just had to change it a bit to load the saved inventory properly.

You can refer to: