Hello Everyone,
I am attempting to create some ‘reusable assets’ for my games and one of them will be set of scripts and prefabs for inventory management. I know there are plenty of tutorials - but all of them do things differently. I am more interested in ‘professional design’ of the feature than actual implementation.
I am having a Scene where several items are lying on the “floor”. Some of them are wearable (in different slots - armor, weapon etc.), some of them are usable (potions, spells etc.), some of them unlock access (keys).
Now what I am trying to achieve:
- Create an inventory system with slots
- Player character has inventory but so do enemies/NPCs(however they do not pick up the items)
- I am trying to minimize the number of necessary scripts, keep it nice and tidy
My current idea for the approach is:
- Have a Inventory script that can be attached to any character. The Script holds collection of Items (kind of backpack), slots for armor/weapons/shield
- Have a InventoryManager having methods for collecting items, throwing away items, quick slots etc.
- Generic Item script that holds all the objects description (name, type, slots that the items can fit in, all the details (defense, attack, path to icon sprite, path to sprite when used), also some methods like ‘use’, destroy’.
- ItemFactory that holds ‘details of all items’ and uses them to Instantiate the actual Items.
Here are my questions:
- Is this type of design a good practice? Is there something I am not seeing? Any problem I may be running into?
- Should I keep the data of the objects in files and load them at the beginning of the Scene?
- What Design Patterns should I look into around the inventory system? Is there any particular one that is generally used for things like that?
- When the player grabs items from the floor, should I destroy the game object and create ‘simplified’ version to put in the collection or rather keep it all the time without destroying?
- Is it better to use generic class “Item” that has the whole state with parts that are not relevant (e.g. attack for armor) or should I rather split the items into separate objects that extend the object Item?
Kind regards,
Piotr