To make things short, I am an experienced unity dev (8+ years experience, wrote Behaviour Trees, GOAP and such stuff from scratch).
How do you handle runtime data in your inventory systems? Things like durability, fill amount of a potion/bottle, items that can only be used once every two minutes, …
Let’s say we have a big inventory, something like a skyrim inventory at it’s limit. 3000 items.
Each item has a Type, represented as ScriptableObject (icon, description, reference to the Prefab).
Obviously we won’t copy those ScriptableObjects because it would create a lot of useless data, instead we just reference them in our PlayerInventory : MonoBehaviour
.
This means, we can’t save runtime data in our Item : ScriptableObject
.
Also we can’t save it in our ItemInstance : MonoBehaviour
(which is attached to the GameObject representing the Item as 3D Object), because we would have to keep an instance to all those 3000 items in memory, just to alter some Data.
Which leads to the big Question: Where should we store runtime data?
An obvious “place” would be the PlayerInventory : MonoBehaviour
. Maybe we have some Slot
class there, containing a reference to the Item : ScriptableObject
and int amount;
- but we can’t extend out Slot class to contain all the possible runtime data of all our items…
We could use a shared dictionary, where each of our items could read/write from/to, but this would lead to a lot of magic strings and overall bad performance (when called every frame).
We could create our own component pattern inside the Slot class, using plain C# Classes and the [SerializedReference]
attribute - but renaming such a class would break all those references (unless this is already fixed by unity?).
I have no answer. Best I can think of is using ScriptableObjects for the custom component pattern and copy them for each item that needs runtime data.
But I wonder if anyone has a better solution? (maybe avoiding the (small) overhead of ScriptableObjects?)