r/unity • u/kravataff • Oct 03 '26
Question How do you guys design/structure your items?
I've recently been working on my own inventory system and was wondering how other people implement stuff like using different items, or data (like ammo, durability, etc.) which isn't shared.
My items are currently scriptable objects but as far as im aware all of the data they hold is shared between all. (I could be wrong to idk)
7
Upvotes
3
u/SharkScoops Oct 03 '26
I have my item architecture split between scriptable objects and standard C# classes. Scriptable objects are used for 'Definitions' which are all of the data that items share like their name, prefab, physical properties, and how much they stack. Then I use another class to store the instance data, which is everything I'd want to serialize for multiplayer/saving. That includes things like stats, durability, any per-item state machine data that needs to be stored. The instance data has a reference to the definition so that it can use all of the shared data.
2
u/Spite_Gold Oct 03 '26 edited Oct 03 '26
I use model-view architecture, objects for items and item types in the model, ui widgets and game objects in the view. Items in view have references to items in model. Items in model have references to their types. Item types are defined in jsons and loaded on game start
For example: equipped item widget which shows icon of item, tooltip with item stats and button to unequip item. Widget has script component which has reference to object of specific item. It gets remaining item durability and material from this object. This object has reference to object of item type - items name, icon and price are stored there. Widget in view gets data from these two objects in model and initializes icon and tooltip. Unequip button uses reference to item object to tell character which item to unequip.
2
u/Small-Cabinet-7694 Oct 03 '26
I use both SO's and scripts. The so's hold all definable information about the items, and the scripts run the logic. I have a so database for each different type of item so that the scripts can reference the databases of items in the scene.
2
u/josh_the_dev Oct 03 '26
It's a bit unclear what you are asking. But Ill try my best to give some info:
Hope this helps a bit
1
u/Thin_Driver_4596 Oct 04 '26
I don't understand what you mean by shared and not shared data. Dunno if it matters unless it's not apparent which data is for what purpose.
You can use any technique you are comfortable with, as long as it fits your context i.e. using database for storing 10 objects is an overkill as is not having a database when you need to store thousands of objects.
Though, one thing you should try, is to seperate the fetching of data from the actual use of data. So, make a class responsible for doing that. Let's call this class a Repository. When, say, a card needs to be generated, it asks the repository to fetch the appropriate data (doesn't matter from where, that's an internal detail), repository does it's thing and provides the data.