Hi, so I have recently been watching different videos, and reading different tutorials regarding creating an inventory system using scriptable objects. I’m comfortable with how to create an inventory system myself, but scriptable objects are still fairly new to me. One thing I kept noticing in these tutorials is that they were still using an ItemDatabase (a scriptable object dictionary of items usually) to store items. My question is why? Scriptable objects can be referenced directly by anything cant they? This doesn’t really make sense to me right now, and I’m sure I must be missing something…
You can use ScriptableObjects to hold data about items, but only if that data doesn’t change during your game. So you can think of them as “item blueprints”. For example you can have a “Small healing potion” Scriptable Object that stores its price, how much it heals etc. But any data that changes in the course of your game and you need to persist across playthroughs, that has to live elsewhere. For example, your player’s “inventory” of items cannot live on ScriptableObjects. They do not persist their changes across play sessions.
Hi!
I do not know exactly what video you talk about, but I have ItemDatabase to reference all possible items there so that I could resolve items by their ID (or name). Otherwise, without the ItemDatabase Unity will strip out all non-referenced items from your final build.
Perfect, its as simple as that. Thank you. Although, why would you even want a non-referenced scriptableobject included in your build? Hmmm…
Thanks for your input, but wasn’t quite what I was getting at. Sorry if my original post was unclear.
My game is online so it is possible to receive a server command containing the ID of an item that was not referenced from existing Unity scenes.
Or you can have some text data files (JSON, XML, etc.) which can have textual references to your items but Unity knows nothing about it.