Hi everyone,
So, I’ve seen these two talks about scriptable objects mentioned in this article:
https://blogs.unity3d.com/2017/11/20/making-cool-stuff-with-scriptableobjects/
And now I’m completely stuck!
I’m working on an inventory system and I would like to modularize what I have so far. I’m using scriptable objects already, but I think I could do much better. At the moment they are structured like this:
ItemBaseData : ScriptableObject (base blueprint for inherited ItemData)
This has lot of variables that EVERY item in my game should have, like:
[SerializeField] private string itemName;
[SerializeField] private string itemDescription;
[SerializeField] private float itemWeight;
[SerializeField] private int itemValue;
[SerializeField] private Sprite itemIcon;
Etc. etc. Pretty self explanatory I think.
Now this branches off into different categories like weapon, armor, consumables etc.
ItemConsumableData : ItemBaseData (potions, food, beverages etc.)
Naturally this has everything the ItemBaseData has. But now this should have two more variables like:
[SerializeField] private int itemSatisfyHunger;
[SerializeField] private int itemSatisfyThirst;
[SerializeField] private int itemHeal;
[SerializeField] private int itemDamage;
And it has it’s own UseItem() function which checks if itemHeal > 0 and if it is, it uses Heal() to heal who ever used the item. The same goes for damage (rotten food, or poisonous berries or what ever).
ItemWeaponData has weaponDamage, ItemArmorData has armorDefense as extensions to the ItemBaseData.
The ItemBaseData class has public getters for its properties. The problem with this is: How to access the new values of the inherited Data classes? For this I use functions in the ItemBaseData class. Not elegant in my opinion. So since I do not want anybody to change the values of the itemDatas they are all private. And once a GameObject like an inventory slot wants to have an ItemBaseData as input data we can’t just say: display the satisfyHunger value on the UI. Because we can’t access it from ItemBaseData.
This means, that I need a function like this to get the default of 0 if the item is a weapon, for example:
public virtual float GetSatisfyHunger()
{
return 0;
}
I override this class in ItemConsumableData:
public virtual float GetSatisfyHunger()
{
return itemSatisfyHunger;
}
This is only one example of things that feel sooo wrong!
What would be the right way to manage this?
My dream scenario would be this:
I have an Item class that can have a list or dictionary of properties. These properties are plug & play. And the display UI of the inventory just takes what ever it gets and displays it. You can have dreams ![]()
How to achieve this?
In order to achieve this I would have to use a extremely granular workflow like in the Game Architecture talk. I would have a SO blueprint for FloatValue and use it like this in the inspector: Create new ItemProperty > Name = BreadSatisfyHunger > Value = 10f;
I would have to create a SO for EVERY item, for EVERY property this item has. I would end up with maybe 10 properties for every item. This feels wrong again. Then add it to the dictionary of properties. And so on.
What ever I can think of, when I reach a point where I want to start running and implement it, it feels wrong again.
How would you guys go about this?? Where am I thinking wrong?