I have just got my save/load system working but have found scriptableObjects are not serializable.
What I am saving gameplay wise, is an inventory with items.
I have given the system some thought and came up with the below solution. To load, it will simply be reversed. (Excluding the scriptableObject)
Would this solution cause any complications?
Anything I missed?
Will it work? (Looks like it should in my eyes)
General comments?
So that Idea is actualy good BUT i dont understand how your Inventory doesnt save its data?
I also have an ScriptableObject(Inventory) and also Items(ScriptableObjects) , after picking up some of my Items, they get stored in my ScriptableObkject and that one in fact gets saved automaticaly … without the need of setting it up in any class to save it afterwards :o
@Terraya “after picking up some of my Items, they get stored in my ScriptableObkject and that one in fact gets saved automaticaly … without the need of setting it up in any class to save it afterwards”
Scriptable object won’t store your data automatically, it only might do that on current game, when you restart your game, you start with default settings. In Editor it might seem like it does save the values as you are changing your asset file values during runtime, and when your exit play mode your values are not reset.
so it depends on your game what you would like todo,
if you want to save the files in a Json which get stored in PlayerPrefs, then your idea is good (thats actualy what i have done on my mobile game) , its just sometimes messy so take your time to make it clean
I think that would work, or at least I’ve used similar setup.
Also, if your items don’t have any changing values (like wear, hit points, whatever) you could store items in inventories, loot drops and when saving only as a list of item IDs.
When you need item data (like description, icon, sprite) you can get the items from some central item “database” with its ID. Item database could be just a scriptable object with a list of items for example.
Sorry I misphrased my question
What im wanting to know is how does one make a database from a scriptableObject?
In your case with Strings, is it with two lists? One containing the string and the other containing the item?
public class InventoryItem : ScriptableObject {}
[Serializable]
public class Inventory {
public List<InventoryItem> items;
}
Or, if you need counts;
public class InventoryItem : ScriptableObject {}
[Serializable]
public struct InventoryEntry {
public InventoryItem item;
public int count;
}
[Serializable]
public class Inventory {
public List<InventoryItem> items;
}
The problem there is that the serialization only works if you use Unity’s serializer, which is only available at runtime through JsonUtility. If that’s a no-go, then your original setup is probably better.
Though for your initial setup, I would do this instead:
[Serializable]
public class ItemObject {
public string itemName,
public int itemValue;
}
public class Item : ScriptableObject {
public ItemObject item;
}