Andy Connacher - Architecture and 3D modelling portfolio
Andy Connacher

Real-time 3D Artist with a background in Architecture

︎ About
︎ Blog
︎ Contact

Andy Connacher
Portfolio




Making my first game in Unreal Engine: Part 3 - Inventory System
12th May 2022


This blog post is part of a series of blog posts about Bard Game!

At this point Bard Game comprised of:
  • Playable character - the Bard
  • Roaming AI Peasants
  • Houses

To make the world more interactive, I began implementing what I’ll refer to as the core systems of Bard Game which were:
  • Inventory system
  • Quest system
  • Dialogue system

This was a much bigger undertaking than I anticipated as I had watched some YouTube tutorials on the subject but none of them really worked the way I wanted my inventory to work.

I also went into it with very little knowledge of UE5 but the journey this project took me on hugely improved how I now tackle issues and approach things when programming so I really wanted to write a blog post about it!

In my head I knew what I wanted the inventory system to do and how I wanted it to work but I had a lot of trouble translating that into UE5 so naturally I did what anyone in my situation would do:

Ask someone who is miles better at programming than you how they would do it - i.e ask my girlfriend, Geeta, for help.
Playlist of all Bard Game demos






Planning

As a disclaimer, Geeta is not a “gamer” at all and she knows less about UE5 than me but she does work in “Big Data” and is what can only be described as an oracle of many programming languages so handling data moving in and out of databases is like her bread and butter.

I explained to her what I was having trouble with and she just picked up a whiteboard, wrote down my problems and helped me break them down in a logical, manageable way, starting with:
1.    What data would be stored in the database?
︎ For me, this would be items in an inventory

2.   What format would the data be?
︎ As each item would store multiple variables such as ItemName and IsQuestItem? etc., UE5’s Struct variable seemed appropriate.

3.   What format would the database be? 
︎ My immediate thought was to store the structs in an array but Geeta suggested a Dictionary (a.k.a map) would be more appropriate as each Key in a dictionary is:
a.   Unique
b.   Has a Value assigned to it - this could be used to represent the Quantity of a given item in an inventory.

This gave me enough to start trying things out in Unreal!



The whiteboard - alien in the bottom right corner drawn by Geeta



Inventory Component

As I wanted ANYTHING in the game to potentially have an inventory (for example, a tree could have an inventory which contains an owl for a quest, I don’t know!), I wanted to program it in such a way that it could be applied to any actor in Bard Game.

The best way to implement something in this manner would be by creating an Actor Component blueprint.

This way, you can program all the logic in one place and then attach it to each actor, rather than copy & pasting all the code for every actor you want to have an inventory - nice and efficient!

I started by creating the core functions the inventory system would need to function:
  • A way to access (open & close) the inventory
  • A way to add items to the inventory
  • To check if I’m looking at the player’s inventory or not



Inventory component containing core functions



Inventory system logic

At this point all I had was the pieces; I had made some test items, given them an ItemStructure each, created an inventory dictionary for the inventory component - now it was onto the fun stuff - programming the logic.

I started with the AddItemToInventory function.

I have to say, it was really nice to have to think and use my brain to figure out how to code this and even more satisfying to get it working robustly!

I then proceeded to flesh out the other functions, moving onto...


AddItemToInventory function




Inventory system user interface (UI)

Navigating Unreal Engine’s UMG UI system was extremely difficult and unintuitive for me as it has a very steep learning curve but it helped that I had a very simple and clear idea in my head of how I wanted the inventory component to interface with the UI.

I just wanted an inventory window that would be populated with Key : Values (Item : Quantities) found in the Inventory dictionary.

In summary, I looped through each item in the Inventory and used the variables stored in each item’s ItemStructure to create a UI element (widget). These widgets would act as individual slots and go on to populate the inventory window.



Items as slots in the inventory window



Chests & containers

The last thing to do was to add some additional functionality which would allow the player to take items from a container’s inventory and add them to their own inventory.

Everybody has chests in their game so I thought why not be wacky and zany and stamp my originality on Bard Game and instead put a fridge in the game?

So I modelled, rigged and animated a fridge and put it in Bard Game.

Another little bonus test I gave myself was to populate the container with the items in the inventory and have them disappear as items are removed - just a fun cosmetic feature!


Inventory system demo




And with that, the inventory system was complete! It took months of work learning the engine but the process put me in a really good spot and showed me that I could come up with these sorts of systems myself if I really thought about it enough and the fulfilment I get from collecting items in Bard Game now is truly unending.

Thanks for taking the time to read this blog! If there are any concepts you want to know more about feel free to contact me by either of the options below!

Take it easy,

Andy


If you require 3D modelling services or you if you just want to talk about 3D modelling, feel free to get in touch with me here or on LinkedIn!


Andy Connacher - © 2023