Best practice to store and load a specific set of objects?

Hi all

Im wondering what the best way to store a specific set of objects always available to my game. Im making a card game and i want to be able to randomly generate a deck of 100 cards from some sort of stored list of predefined cards that will stick with the player for the entirety of the game. I want to be able to save the deck after changes are made to it and also have several different decks of cards for several different players.

How would i go about creating this dataset of individual cards that can be put into decks when the game is running?

Should i make an XML file containing information about each card?

Should i hardcode the cards into one of my Classes?

What would be the best practice approach to this?

Thanks in advance :slight_smile:

(Edited the question to better reflect what i actually wanted to ask xD)

A relatively simple “Unity” way is to make a “cardHolder” gameObject, with the cardHolderScript on it, then set it all in the Inspector (drag over all the textures, set values… .) For multiple scenes, make it a prefab.

The biggest risk is that it you can lose chunks of data if you, say, change array names (like renaming filled Texture2D[] CardFaces;.

Technically, this is the “use a file” approach, since Unity is writing all of this data somewhere. Probably in a more compressed format than XML (or not) and not readable by you.

For small data (probably not your case) you can use player preferences.

I have also used xml for saving data, it doesn´t seem like a bad way to go, although I don´t consider myself an expert.

The best option (to me) is using SQlite (which I am pretty sure is available thanks to .NET). It´s without a doubt the fastest way organize your data, given that you know how to use it… I didn´t like it at first but I had to learn it in my job and now I can´t help but respect it.

Well I would create an Array of ints for each player. So the length of the array would be the number of cards and the number the int[| returns would be assigned to specific card.

So then you could just use PlayerPrefsX ( with the command PlayerPrefsX.SetIntArray().

And then when you can load the deck later on again using PlayerPrefsX.GetIntArray() and just make the process you did to assign the cards backwards.

It’s easy and you don’t have to store a huge amount of data.

I also think that it is faster then xml serialization :wink: