Bare Bones Inventory Functionality, Using ActorComponent, DataTable, with a Slot Layout

Hello Reader,

So, I have been trying to figure out for a long time how to set up just a basic Inventory system that I can use for all of my future projects. Tutorial after tutorial, I have watched, and I have learned a lot from them. The only thing that appears to be consistent between them is that they all have, for the most part, the same functions. i.e. “AddItem”, “RemoveItem”, “FindSlot” and so on. However they are all built slightly different, with the different structs info, per tutorial.

That being said, this is what I am trying to build. I have already done most of the leg work for my UI Layout to include the Inventory Window and Inventory Slot widgets, along with a few additional ones that I will need for my system.

Want to include:
-WorldItem / PickupItem
-Inventory to be Attachable to: Player or Backpack or Container(Like a chest or something)
(For Example, I may want one project where the player just has an inventory. Or another project I may want the inventory to be tied to a Backpack, where the contents follow the backpack rather than the player. I Figure this would be done using an Actor Component)
-Drag Item From Inventory to World or Container
-Should use a DataTable with my ItemStruct.
-An Editor Function I have been trying to figure out on my own, but have since failed. For my Row Names, I am using a numerical ID system, as I plan on have a pretty large index. So I am trying to Get the RowName from the Table and using the ItemName via a Lookup. so that when I place the Pickup in the world, I can type the Item name, vs the Row Name(ItemID). (If this isn’t Possible, then I suppose I could take an alternative route where I just Add yet another Variable for the ItemID)
-My Pickup I want as a look at, rather than stand-on or Radius. However I was having a hard time trying to figure out how to use the “isValid” output and always returned as NotValid (Im sure part of this problem is that I was following a tutorial using a radius check to get the actors, while I modified it to use a Line Trace and HitActor): Part #1 - @24:00
-And of course I need it to be replicated for Multiplayer.

I will also need to be able to implement an ActionBar/HotBar, Equipment Window, and Crafting. But I haven’t got that far to begin trying to build those. Attached is the UI I put together for my Inventory.



Bottom Line, I want to make the system myself, however I need some help / guidance figuring out what Arrays I need/should to use for the inventory contents and how to use the Item data for my items and in it’s most basic form, how the different functions should be built, so that I can expand on them.

Ahoy Quickshot991, welcome back!

Your current situation is quite large and you may need to break this down into different questions as you implement each part of your inventory. I understand you have viewed many tutorials and it seems you have a strong grasp of what you want.

Have you considered checking out some free assets from the Marketplace? At the least, you can reference some of the implementation for your game.

Example: Inventory System by HowToCompute
This system contains:
Inventory, pickups/dropping
Chest storage and basic crafting.

This pack does not include any weapon functionality but I find this to be a good base to an inventory system that is open enough for you to consider expanding upon it at a later date.

I hope this pack gives you additional insight into your systems.

Yes, I have actually looked at that one, it has been awhile since I last looked at it, so I could revisit it. I think the enumeration tables is what was throwing me off, when comparing to systems that use a data table for adding new items. It is also possible that when I first looked at it, I didn’t really understand what I was looking at as much as I do now.
I can definitely re-do my post and try to break it down into smaller questions.

Goal: To have the InventoryComponent attached to the player, and the only nodes in the player blueprint are to open/close the inventory. With most of, if not all of the inventory code contained in the Component, UI Elements and Pickup Actor.

For starters, I could ask, what seems to be the norm, as far has how many structs are typically used just to get data into the inventory? Also what the struct should contain at a minimum.
If I am Missing anything, let me know, but I figure it’ll have;
-ItemName
-Texture2D
-Mesh
-Amount/Quantity
-isStackable?
Is it more efficient to have 1 struct with all the Data, or Multiple Structs. Multiple Data Tables for the Items, or just 1? I have seen both in some of the inventory systems I have from the market place and in tutorials.

Oh, Also, If I want the system to use weight and/or volume, should I add those to that struct?

Hello, hello again Quickshot991, thank you for the reply.

Honestly, I felt the same way when I first saw the inventory product too. Your question made me revisit it and yeah, a bit of experience really changes things for the better.

Alright! Let’s get into your questions:
Three ingredients I would consider:
DataTables, Structs and Enums.

Your list looks decent for an inventory system. You may also want to consider adding a class variable to your struct that handles weapons. You will have to do to behind the scenes logic on using the weapons, but that would be a good variable to include nonetheless.

-Weight. This is a personal decision (depending on how pedantic you want to be). You can also measure encumbrance by the amount of slots used, kind of like in 7 Days to Die (game made by The Fun Pimps).

I would also consider having multiple structs/dataTables. Especially if you intend to have a whole crafting system.

This is exciting. I really hope you get a working modular inventory system down.

Okay, So I have been working on setting up all the functions, according to the Example you suggested. Of course I made a few minor tweaks, to it for toggling the window open and close(which works fine). I also changed the Item Enum to a Name Variable. I can’t test the functions just yet however, as I am currently stuck on the InventoryWindowUI. For what ever reason, I cant seem to get the Slots to populate inside the window. To include setting it up node for node to the example.

In the Example they create the widget from the Actor Component, and Populate the slots from inside the InventoryWindow Widget. Which seems to work fine in the example, so I am a little lost. Any suggestions? I can post some screenshots in the morning if you need them.

Okay, two more questions.

Given the goal of modularity,
Is it better to put my Inventory Widget directly onto my HUD Widget as a child, or is it better to create the Inventory Widget from Begin Play and adding it as a child via blueprint?

Second Question,
Inventory Widget and Slot Widget; should I add the Slot to the Inventory from the Inventory EventGraph, or should I call it from the Inventory Component and Add the slots from there?
(Edit): This was an embarrassing mistake. I was pulling the Index Variables from the wrong place. Instead of the out pin on the for loop, i was grabbing the Variable, itself. lol

Still wondering about the first question though.