Hi.
Currently, I’m getting into Unreal and want to try to do things smarter and more flexible.
I’m curious how would other developers approach the implementation of an inventory system with ambiguous inventory item requirements.
Imagine that we have different types of weapons in the game, like
guns or bows, throwables and melee weapons. And we want to store them in some inventory entity, but they all have different sets of properties representing their state in the inventory.
For example, I’d like to remember the state of ammunition in the magazine when I unequip guns and put them into inventory, all guns have their type of ammunition. While throwables and bows are straightforward, you load ammunition every time you equip them. Melee weapons don’t have any of these properties.
What complicates the situation is that each weapon has its type of ammunition and on top of that, I’d also like to have a limitation to store only one weapon of type primary/throwable/melee.
I was thinking about using gameplay tags to reflect the state of available items in the inventory, but the thing I can’t figure out is how to store the state of weapons in the inventory in a convenient way without hardcoding the behaviour per each weapon type.
Could you please share your knowledge on how would you approach the design of such a system, keeping it abstract and flexible? What engine or CPP entities I can try looking into to satisfy the requirements I’ve mentioned?
The answer to this question probably covers the next year for you
All this stuff to do with inventories and weapon states has been done to death on youtube, but you won’t find one all-encompassing tuut.
I will tell you that you’ll need to find out about blueprint inheritance for the weapon / pickups
Each weapon BP stores its own state within itself. Between weapon uses and game sessions, you’ll need the save game to manage the states of the weapons
Thank you for your answer. Maybe I wasn’t clear with my question, I know what inheritance is, and I’ve already implemented some system to keep track of mission progress, however, it is not the point of the question.
You are completely right that YouTube tuts completely miss the architectural aspect of writing software, and often are just making things even worse in some way.
I’ve already thought about 2 different approaches:
The first one is similar to Lyra’s inventory, using item definitions, instances and fragments
The second one is having a kind of database in DataTable which knows all [gameplay tags - weapon actor - weapon inventory instance - weapon inventory state - weapon ammo instance] associations. And query it every time I do something with my equipment or inventory.
But I can’t wrap my head around how I can make any of these work, so I’m trying to get some advice and thoughts on how could I achieve this behaviour, that’s why I’ve created this question. I know that software development is opinionated, but any advice from seasoned developers might help me push myself to some idea of the implementation.