How do I go about making a simple inventory system in c++?

All I want to do is make it to where if I pick up an item the item icon shows up on the widget from right to left. I want to do this in C++ though, and there’s not really a lot of tutorials showing you how to do that especially for c++ and I don’t really want to watch a 10 hour series on how to make an over complicated inventory system when mine is just pretty simple that I’m trying to go for. Here’s the widget that I made for it and what I’m trying to go for

I already have a way to pickup the items that I want, now I just need to figure out how to get an image to show corresponding to the item I picked. If there’s any advice or anything to point me towards the right direction that would be great, thanks.

Most approaches at a very high level pretty much boil down to this:

  • your player has an Inventory which is an array of items (nothing to do with the UI)
  • your UI has an array of inventory slots (4 in your picture above)
  • using a reference to the player’s Inventory, the UI would update each inventory slot icon based on the corresponding player Inventory array index

There’s a hell of a lot more to it. But at the core that is what most inventory display UIs do - create a visualization of the player’s inventory array.

Make 2 classes, Item and inventory.

class UItem : public UObject
{
	// define your item. Like FTexture Icon;
}
class UInventory : public UObject
{
	// TArray<UItem*> Items;
	// Add(UItem* item), Remove(UItem* item), isFull()......
}
  1. Inventory class should make sure that items is properly handled. Keep item simpler.
  2. On your pickup event. Call something like this
bool OnPickup(PickUp* pickUp)
{
	auto newItem = NewOjbect<UItem>();
	newItem->MakeItem(pickUp->Icon);
	mInventory.Add(newItem);
	UpdateUI();
}