Inventory system for a 2d game

Need a bit of help with making a inventory system for a 2d with no player character. Would i be able to use the game instance to effectively store an inventory system? And how would you add and retrieve items from it? Also what would be the right way to have items effect the character i.e if something give +5 strength how would I have to structure it to make it work on equip and unequip? Please be as detailed as possible because I’m quite lost at this point, thanks in advance

Can you please be a bit more detailed?

A 2D with no character, but items effect the character? Is there a character or not?

Best place to keep information is the save game:

1 Like

I’m using the game instance to simulate a character, and different buttons change the stats for the “character” to simulate racial stats. Sorry for being confusing.

You can use the game instance for a character, if you only have one character. But you will still need to store it all in the save game in between plays.

True but I need help with creating the actual inventory system most of all, I’ve already made the inventory widget and the item slot but I’m not sure how I should set them up.

Have a look around you tube, there’s enough inventory systems on there to kill and small pig…

Hey! in my Case, I’ve the Same Problem. My Game is a 2D Text based RPG like a single Player Pen&Paper Experience. Ive saw a lot of Inventory Tutorials on Youtube, but all of these have a Base in 3D Space, like 3D Actor Components etc etc. I only need a Text Based Inventory like the old School Final Fantasy Games. No Icons, only Text and Quantity function. Have anyone a Source for a good Tutorial?

Thanks

I think you’ll find the 3D tuuts are pretty much what you need, you just don’t need to do the graphical parts, which makes it much easier :slight_smile:

You’re still going to have the core components, like item type, quantity, save game, etc…

Iam a dumb idiot. Instead of very complicated inventory Systems with structs ans arrays like in the most inventory Tutorials, i now simply use a Name/Int Map in combine with an Data Table and thats it. Works very well. The only tricky part is, to clear all the children of slots in the Inventory Widget, before generate it again with an for each loop.

1 Like

Excellent :slight_smile:

Hi me again! After a couple of month i must reworked my game and still use an DataTable/Int Map for my Inventory. Add and Remove Items are working very well. but now i need to unstacked some of the World Items, like a Typ of Weapon or something. But how can i add the same Item with the same Data Table Data (different is an “IsStackable?” Boolean) in my Map? Hope you understand me?! Thanks :wink:

Wouldn´t that be the reason, why the others used structs and arrays for their inventory?
The struct can contain all the Item infos/variables like “Item ID”, “IsStackable”, “Amount” etc., and the array holds all the structs/items - and if i am not mistaken, unlike a map, an array can have several items of the same type with just some slight changes in their variables.

The IsStackable variable you would want to add to the Data Table, not to the Map. Think of the DataTable as the ‘template/definition’ of the item and the Map as the stack instance. The Map shouldn’t need to know anything about the default item info. (The only time the Map should have additional values is if you’re going to be adding some form of ‘weapon modifications’).

Then any item (inc. weapons) that you don’t want stackable will simply have this variable at true. Alternatively, instead of a IsStackable bool, you can use a MaxStackSize integer. This allows you to have only one item per stack, or perhaps 12, etc.

As @Suthriel mentioned, you may want to consider moving to an Array as a Map means you can only ever have one instance of a particular item, which typically isn’t what you want but maybe that is what you want.