I regularly create inventory systems during my homework projects. I always design them so that it is easy to modify the inventory and add new items.
I always separate the inventory from the user interface so that I can easily place inventories on other elements of the game, such as chests or enemies.
Whether I use Unity Engine or Unreal Engine, I always take the same approach.
Inventory System
System
I always start with the items. I create a Scriptable Object (Unity)/Structure (Unreal), in which I add variables that contain various information about the object, such as its name, description, etc.


I then create a script (Unity)/Blueprint Component (Unreal) to create the inventory system. This is where I store the character's items with all their information and define the inventory settings.
In the example, you can see that I can define the maximum size of the inventory as well as the distance at which items appear when the character wants to drop them.
Part of the inventory system code in C++.
This function allows you to remove an item from the inventory by specifying its ID. The system then checks whether it can find an item matching the ID specified as a parameter. If so, it removes the requested quantity.


User Interface
Next, it is necessary to be able to display this inventory. I then create a user interface that is independent of the inventory. Each time the player decides to open the inventory menu, the interface retrieves the inventory information in order to display it.

So, for each box, I check whether there is an item in the inventory at that box's location.
For example, for the third box, I check whether there is an item at index 3 in the inventory's list of items.
If an item is present, I display its information in the box; otherwise, I leave the information blank.


