GameObjects + inventory + load/save game

Got a small question while I’m at work :slight_smile:
I’m preparing to create a inventory system for my 3d game.
There are gonna be money/guns, etc around the terrain.

Got no problems with inventory script, but more like with a save/load game.

On a new game it’s simple. Objects are randomly throwed around the map and player can pick them up.
Tricky part starts when I load game. How to tell game that user has already picked up that item and it shouldn’t be put in the world?

Open to any suggestions :slight_smile:

Sounds like a finite (specific) list of items you’d have in spots. You could number them and check against the player’s list with a comparison of some sort.
If every item was unique you could do a similar comparison, checking their uniqueness.

I would guess if you make save game you have to somehow store objects in inventory, probably using some object id. Then just like methos5k said do a comparison upon object creation.

I agree with keeping a list of the items generated, but I have a different approach to suggest.

When the world is created, generate the list of all lootable items. This list is included in the save data, and is used to place the items in the correct place each time the game is loaded. When the player grabs the item, just remove it from the list. Next time, it won’t be loaded, plus there will be less data to load, and no comparisons will have to be made (potentially thousands).

2 Likes

Hyblademin has nice approach too. Though more complex saves because you will have to gather data from different sources and potentially if you have lots of items save huge list to save and if you move to next level then you potentially wont need all items in list depending on how your game works.

Whatever approach you take keep it in line with your architecture thus far.

Thanks for the responses!
Gonna try out Hyblademin suggestion

Hyblademin has the right idea, more or less. Just make sure that your item editor counts up an ID for each new item. Storage of item status shouldn’t take much space at all (ID, position, boolean structs in a dictionary, for example).