Inventory System with Save Game

Hi people. So I’m working on this game where I wanna give the player the choice to choose from a variety of skins for both the knife and the cake. I’ve never worked with save games or inventory systems before, that is why I wanna share with you my approach so you can advise me.

Here is what I’m thinking to do. I’d store all my knife (I’ll use just the knives for example) button images in an array within the main menu widget and create an integer variable within the save game that would would check which knife is selected when the GameInstance is initiated and assigns the correspondent item from the image array.

This sounds confusing but I hope you get what I’m trying to say.

I might be missing the point, but wouldn’t it be more convenient to save the (soft) asset reference rather than its ID, and then be forced to fetch it from the array.

The above picture (psedoscript) demonstrates the retrieval after loading the save game (soft assets need loading, though). This way you wouldn’t need to worry about keeping track of IDs, which can be a royal pain in the neck at times.

In short, save the asset itself, not its ID.

1 Like

Thanks for the new perspective. I don’t know if it’s optimal but I thought I’d choose an integer variable because it would keep track of both the image to display and the knife child BP that’s supposed to spawn in the level.
If I understand, following your method, I’d need 2 variables, one for the image and one for the knife BP. How can connect between them?

How can connect between them?

Somewhat hard to advise something tangible without knowing the scope / structure but do consider the following:

  • normally, one does not save variables 1 by 1; even for a small, simple game that’d be really awkward.

  • here’s a struct (just a bunch of data) that represents an in-game item the player can carry:

Any default values should be in the class itself, variables that can change, should form the rest of the struct above. Default skin does not really belong here for example, it can be tucked away in the class.

  • over the course of the game, the player will acquire new items and, eventually, we’ll need to save them (you can’t save a spawned actor, so you save the data that defines it):

  • when you load the game, you respawn the actors and feed them their data from the save game:

The above is more of a top-down view hoping to answer this:

I’d need 2 variables, one for the image and one for the knife BP. How can connect between them?

Structs can associate data, it’s a container.

1 Like

I understand much better now, Thank you for your time :slight_smile:

I’ll just add that because of how cumbersome the native saving system can become (as the scope grows), amazing plugins were made, simplifying the whole process and adding tons of functionality:

Thanks! I’ll look into it.