What method to use for storing and retrieving data for an OFFLINE RPG

There are two different types of info that need storing and retrieving

  1. Game data

  2. Character data and progression

  3. Game data is stuff that exist in the game. For example, the equipment and their properties, items (like potions), spells etc. Those are staple and always exist and have to be stored somewhere in order to be accessible.

  4. Character data and progression is volatile data. That includes level, exp points, hp, mp, what equipment they use, what class they are what spells they have selected etc. Here is the data that typically goes into a “save file”.

(If there is any extra kind of data that needs to be stored please let me know)

So, what I’m looking for is the optimal way to store these. I have researched this here and there and this is what I’ve come up to so far:

a) Player prefs are generally to be avoided when it comes to so much information. What is your opinion on this?

b) C# Multidimensional Collection to Store and Retrieve Character Information - Unity Answers → I found this question while searching. It somehow tackles the problem but I didn’t quite get the solution. I understand that creating custom classes for every type of item or spell etc. and I’ll probably do that too but what I’m interested in is where I will save the PRESET item properties (like for example, Holy Sword: +25 atk, Holy element, Slashing damage type)

c) Someone said something about using a database like mysql. Is this the way to go? If yes where do I find examples on this and how do I link the database with the game? Remember this is for an OFFLINE game (so don’t start talking about servers etc). Also, making a DB on an exterior mySQL API and then importing it in the game, is that possible?

Thanks in advance!

For your #1, all that data is stored within the game build, you set how and where everything is in the Editor.

Your #2 is a bit trickier. The asset store as a few save/load solutions: Unity Asset Store - The Best Assets for Game Making is probably a good one because whydoidoit is a pro and knows what he’s doing. Other than that, you could use PlayerPrefs yourlsef, unless you have MBs of data to save. Then a better option would be to create your custom serializer (though I’m sure you’ll find one somewhere) and save the data to disk, like real savegames.

The way you store the data in #2.b within the game is totally up to you. My first thought is to create an enum which contains all your items in the game, You could then have a getter that returns whatever info you need. Presets in Unity are called Prefabs

//outside your Item class
public enum Items{

//Inside your Item class
public static GameObject Create(Items item){
/*Instantiate and return the correct prefab here*/

This approach might or might not work for you, depending on how many items you will have in your game. I’m sure there are better solutions, but you’ll need to discover them by yourself.

Unfortunately no one can tell you what data to save in your game, because we don’t know what your game is like, you will have to discover that yourself, as well.

I would recommend not creating a class for each item, instead create a base class Item that contains all the stuff each and every item in your game has; name pops to mind. You then inherit Item to each type of item i.e. Sword, and give the Sword class each and every property all your swords have.

This way if you have a GameObject that represents a Sword (and has a Sword script on it) you can use GetComponent< Item >() to get access to all properties all your Items share, or if you need the Sword properties, then use GetComponent< Sword >()

Using an SQL database in offline games… My knee-jerk reaction is not to use one in offline games. if you’re willing to ship the database with the game and potentially code some boilerplate code it could work. I doubt it would, but I’ve never tried.