I have an Item class that stores ItemSO scriptable object
public class Item : MonoBehaviour
{
[SerializeField] private ItemSO inventoryItem;
}
My Item SO is an abstract class that stores general info that every item has
public abstract class ItemSO : ScriptableObject
{
public string ItemName;
public GameObject prefab;
}
For every specific Item type, I made another Scriptable object that inherits from ItemSO
public class FuelItemSO : ItemSO, IDestroyableItem
{
[Tooltip("Burn Time of the fuel in minutes")]
public float BurnTimeIncreasePerKg;
public float TemperatureIncreasePerKg;
}
Now everything was working fine, while I was using my Scriptable objects as data containers as they are meant to be, but now I need to have another Item type, where I need to change the values of the variables. Let's say this class
public class ContainerItemSO : ItemSO, IDestroyableItem
{
public float maxAmount;
public float CurrentAmount;
}
I can't seem to find a solution how the base Item class would GET, and SET different data according to the ItemSO. Like let's say it's a water container, and I want to add water into it.
I'm thinking of having an interface IHaveChangableData that ContainerItemSO will inherit from
public interface IHaveChangableData
{
ContainerData GetData();
}
and maybe a ContainerData class that will store the variables, so that I don't store them directly in the Item class
public class ContainerData
{
//No idea how to store ItemSO specific data
}
idk if I'm overcomplicating stuff, but maybe someone could share a solution to this.
Also, should I consider so switching to classes from Scriptable objects if I want to have a coulpe of items with changeble data?
it's not very straightforward to revert runtime changes to scriptable objects, as they're designed around the idea of being configurations rather than runtime data. However if you're looking for a way to do this anyway, my suggestion is not to serialize your runtime data, so for example your
ContainerItemSOclass would look like so:or make it a property, whatever works best for you.
If you want the runtime data be inspectable and serializable (maybe for testing scenarios?) you can create a separate type for runtime data and make a copy on OnEnable