Saving inventory Question

Hello i’m working on my own horror game and i am following this course that shows me how to do it by Aidan Perry. he showed me how to create a inventory system but not how to show it. i kinda made my own script and it works but only to the first slot can you guys please tell me how to save all the slots here is my save blueprint.


image
image

You are calling update inventory slot only on the index 0.

You probably need to loop through the indexes and update them one by one (maybe based on inventory content length? Though without information what is in UpdateInventorySlot it’s just a guess.

Also that cast seems redundant. Check the Note at the bottom of the blueprint.

Hello,

Thanks for youre feedback. in the update inventory is just some code to update the interface so that the information/image/item is good (see photo below) how can i loop the index i cant find a option for that.

And here is what is in update slot if you were wonering.

You can drag of the multiple squares symbol (array) from inventory slots and then call a foreach loop for it. It will have an index inside of the loop. Then try connecting the save game slot after the loop completes (there is a completed pin at the bottom of the foreach loop
forloop

Also looking at the updateinventoryslot function you seem to be setting the variable inventory to just one specific slot feed. That doesn’t seem right.
Shouldn’t the reference to inventory hold the whole inventory?
What type of variable is inventory inside of the function?

Hello thanks for the awnser.
Do you mean like this?

Because that doesnt work can you please tell me how to connect it different for it to work?

The variable in the update inventory was just a poor attemd to save inventory but it did not work haha i removed it now

Are the inventory slots structs? The color would imply that. If so then you are already passing in inventory information into the savegame file.

To load the savegame file you need to do a bit of a different process.

You need to get the Inventory Contents from the savegame file and do a foreach loop
but in foreach loop body you have to get the element (current inventory slot struct) and convert it to the contents of the inventory slot and set it.

Like this?

No, You can set Inventory slots directly from inventory content → both are arrays so one’s contents just replaces the other’s, but you need to still rebuild the ui after loading the contents.

Sorry i dont really get it.
do you mean like this pluggin the inventory content directly into inventory slots?

Yes but you still need to populate the inventory ui slots with information from the fresh inventory contents.

Ah oke thank you very much do you have any idea of how i can refresh this ui?

It depends how the slot widget it setup.

  • Does it hold a struct with item information to drive it’s contents
  • Do you have a function call to set what is in the slot

etc. Depending on the way it’s setup you can implement a function that reconstructs the contents for instance by passing in an element from the array inventory content.

Then you would just call a loop on inventory content and pass it’s element information into the SlotArray => Get[same index as loop] => call function set slot content passing in the element.

Hello thank you again i have set something up and it kinda works?

The problem now i that it add more items than i had before

When i save :

When i load :

Can you tell what goes wrong?

Also here is my save script

from your save script remove the for loop it’s not needed (you are setting the same variable in a loop)

You also need to connect the index when adding items

If you are loading, then you need to clear the array that is holding the old items first before you begin the loop of adding new ones.

thank you so much its works :smiley:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.