Saving data from multiple classes

I am currently building a card deck system similar to that of Clash Royale, and wanted some advice for saving my deck.

My DeckSlot class contains an int for the slot ID, and my Card class contains (amongst other things) an int for Card ID. I already have a system in place for saving cards in my collection, and I do this by serializing the IDs of the owned cards to a file.

My question is now, what would be a good method for saving my DeckSlot data, as I need both the slotID for the deck, and also the ID of the card. I’m unsure on how to create the association, unless I perhaps used a wrapper class containing just these two ints.

After some experimenting I thought a dictionary might be the way to do this. I’ve never use a dictionary before though, and unsure if this is their correct usage.

When saving my deck I create a dictionary that stores the deckslot as the key, and the card ID as the value, then serialize that to a Json file. I haven’t finished with it yet, but I can’t see there being any real dramas, but as I said I’ve not really messed with dictionaries before.

Hi - @ItzChris92

If you use JsonUtility (the built-in serializer) to serialize your data to json, it doesn’t directly support Dictionaries.

You have to use lists to serialize both keys and values. But there is a solution for this if you want to use dictionaries, see: Unity - Scripting API: ISerializationCallbackReceiver

Thanks for the reply. I’m using Newtonsoft so the serialization itself isn’t a problem. I’m just wondering if a dictionary is the best suited solution to what I need to do