Selecting saved list data into a unity list without overriding current list

Discussion and help for Easy Save 3
Post Reply
jonesseries
Posts: 1
Joined: Thu Aug 06, 2020 12:27 am

Selecting saved list data into a unity list without overriding current list

Post by jonesseries »

I have a Master list of all of the Potions in my game, right now its only two but will become 100+ in the future. I have a ItemMaster class and a potionMaster that has a list of ItemMaster. The goal is to save the number of each item and settings the player has, the ItemObject is a SO and does not need to be saved because the Master list should be fixed. I need to set everything in "Item State" and "Amount of Item" to the players saved values.

Code: Select all

public class ItemMaster
{
    [ES3NonSerializable]
    public Item itemObject;

    [Header("Item State")]
    public ItemState itemState;
    public bool itemFavorite;

    [Header("Amount of Item")]
    public int itemNormalQuality;
    public int itemLowQuality;
    public int itemHighQuality;
    public int itemEnchantedQuailty;
}
and

Code: Select all

[CreateAssetMenu(fileName = "New Potion Master", menuName = "Add/Master/Potion Master")]
public class PotionMaster : ScriptableObject
{
    public bool potionDirty;
    public string potionHash;
    public List<ItemMaster> potionList = new List<ItemMaster>();
}
Is it possible to select each sub-key in the saved ES3 file? Below is the 2 potions saved in the ES3 file and the current Save and Load Code. I feel the Load save is wrong but I am just not sure why. I am pretty new to unity so I might just be doing something wrong, so any feedback would be great.

I feel like I should just be able to select the main Key "potionMaster0" and the sub-key "itemState". Is this thinking wrong?

update 8/9: I got it working by off loading the data into a itemTempList all at once, then transfer the data into the master list without overriding the SO. Keeping the SO untouched makes adding items in the future much easier and I don't have to add them to the Easy Save 3 Ref. I still would like to know how you would approach the issue above, is there a better way?
Attachments
ItemState.PNG
ItemState.PNG (22.34 KiB) Viewed 767 times
Code.PNG
Code.PNG (103.58 KiB) Viewed 767 times
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Selecting saved list data into a unity list without overriding current list

Post by Joel »

Hi there,

If I understand correctly, the solution you've provided is the same solution I would suggest.

Just to clarify, it's not possible to load the individual field of piece of saved data. Instead you would need to save each field to a different key. I.e.

Code: Select all

ES3.Save("potionMaster" + p + "itemState", 	potionMaster.potionList[p].itemState);
ES3.Save("potionMaster" + p + "itemFavourite", 	potionMaster.potionList[p].itemFavourite);
// Etc
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply