Inventory in top down game

I have been working on this inventory for some time. I actually think this is my second inventory, but I have I have been iterating on it for so long that all the old code is probably gone. It has also bounced between so many different unreal projects it’s getting pretty embarrassing for me. 😛 I have small pockets of spare time, so I do a little fix here and a little fix there, and sooner or later it finally looks like something, even though it takes time it will get there. Oh, and its very easy to get distracted in Unreal Engine 4, I know. 😛

First I want to talk a little about the inventory and how it is built up. I built it as a component that you attach to a storage unit or a character or any actor. You set the number of slots and rows and you are pretty much done. In the game I am currently making every item drops into the world so there are no need for many inventories or GUI loot tabs, but if I need to build a storage unit for my character, it is pretty simple thing to do, just add the inventory component and then add it to the GUI.

As you can see on screenshot you can access the characters inventory components runtime and for example check what items you have in what inventory component. You can drop an item into the world or you can drop/swap it into another inventory component. The inventory I am currently creating is a little special and might be because it is in fact four inventory components. You can think of it as slots that are unlocked through a item or upgraded piece of clothing or gear. Look at video to see the inventory demonstration.

There are four equipment pieces you can find in world to unlock different slots in the inventory. These can also unlock different amount of slots and are usually multiplied with 2. This is a double edged sword, it opens up for a lot of inventory maintenance when playing the game. Some people hate it, some people love it. I personally love to organize my inventory. It also gives a lot of choices to the player. Do I go with the backpack that opens up 12 slots but doesn’t have any other attributes, or do I go with this new backpack that only have 8 slots but give me additional +30 move speed and +5 intelligence. I am an intelligence hero and need those +5 intelligence, but at the same time having more slots in my inventory is always important. See? It’s a hard life in my dungeon crawler.

This also happens visually off course. It is not that obvious with the pouches, but you can see the mesh being equipped on the character. I have not implement this for everything like clothing or weapons yet, but the code is there for static meshes like weapons and backpack/pouches.

List of possible slot unlock.

  • Body (chest/pants), unlocks 2-6 slots.
  • Backpack, unlocks 6-18 slots.
  • Pouch left side, unlocks 2-6 slots.
  • Pouch right side, unlocks 2-6 slots.

The inventory is, as mentioned, fully functional with items that will give attributes when equipped (strength, evasion, etc). I will show more of that in my post about my character attribute system. Also, when you drop your big backpack with 12 items in it, all those items will be dropped into world together with the backpack.

The items consist of several structures that are fetched depending on what information you need from the item. You don’t need stack count if the item is an equipment item. It will never be able to stack. I made a data table that contains the items, and this data table is used to spawn items into the world. Right now it just spawns a ton of items not taking into consideration level and percent chance. So currently everything goes, this will be changed later. In the data table you can set item name, description, level cap, category, etc.

The tooltip widget of etc item is information fetched from the item and toggled on/off depending on item category, quality, etc. You dont need to show 1/25 on an item that is not able to stack. Some text in the item also changes color depending on the item quality. Most things are done through a simple select node and getting information from the item structure. As I mentioned earlier, every attribute is working and is being applied to the character on equipped.

Other stuff worth mentioning is that if I drag an item, lets say an axe, it highlights where you can drop it. This was done by just checking if the item is equipment and what slot it belongs to. There are also small tool tip over every one of the equipment slots if you don’t have any item in them. Just text telling you what slot is. I am also considering creating small icons in the equipment slots to make it even more easy for the user to connect where to drop equipment items. I need to practice making icons though. 😛

There is also the item animation and the way items drop into world. I went back and forth between using physics and an timeline. I ended up with a timeline and a lot of predetermined drop spots around the spawn drop. I always use a raytrace from top and down to see if there is a “ground” there to drop upon. I dont want items to fall into a space where the player can’t reach. Physics are hard to control and an item might fall of an edge or get lost somewhere. I was going for full control. All items will only drop on mesh with a collision channel called “ground”. Look at the screenshots of how the items drop. The spawn picks a bunch of drop points from a shuffled array. Then it removes those where it can’t drop and then the array repeats if the number of items goes over the number of available drop points. Normally it will never go over. Unless you set the item spawn to drop 30 items and you are surrounded by walls. The array is very long and I just did the vectors in the array manually. It was a lot of manual typing, but I am happy with the result and it may look random, it is not, which is what I am aiming for.

I also added a “item drop” component. You can use it on any actor and the actor will drop items.You can call the drop items event if a character dies or you can tell it to spawn on even begin play. You can set it up to drop a ton of items or you can tell it to drop a specific amount of items from a list of data table names. In a setting, like I show off in the video, the “Item drop” component drops a single item for every equipment slot, a potion, and a note. This I have manually added to a list so that I can get all those specific items and show off my inventory in a way where I can equip on every slot and show of every functionality. Adding the data table row name to the list makes sure I get the item I want. I have split the data table into several data tables. I thought it might be more organized to split them into different groups such as weapon, consumable, armor, etc. Time will tell if I am wrong. 😉 I still lack a experienced when it comes to the use of data tables. Little nervous about this.

There are a lot of stuff going on here and there a lot of rules that need to be implemented. Can you drop a potion into an equipment slot? Can you swap an item that is in equipment slot with an item that is not suppose to be in a equipment slot? Can you drop quest items? What happens if you drop a backpack with items in it? You need yo think about every scenario.

In general I am quite happy with how everything is coming along. There are still some small issues that appear from time to time. Bugs that need to be squashed, but they are pretty minor and nothing game breaking.

I will continue working and improving on it. I also have a plan to have shortcuts on Q and E for health potion and mana potion. This means I need to access the inventory and find all health potions etc. I am pretty convinced it will work fine.

The next post will probably be about character attributes and character system. It is quite the subject and I might regret even writing about it. 😛 If you are looking for a tutorial on how to create your own inventory in Unreal Engine 4 I would recommend looking into
UnrealGaimeDev tutorial on how to make an inventory. Just follow this link. I have seen most of the videos and they helped me a lot. 🙂 Recommended!

Also at last I will add a screenshot from my debug, it just shows a little of whats going into the character system. I talked earlier about the items attributes, here you can see all attributes I have included into a character.


Leave a Reply

Your email address will not be published. Required fields are marked *