Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jokeaccount · Jul 31, 2013 at 04:01 PM · databasedatarpgofflinestoring

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

1) 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.

2) 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) http://answers.unity3d.com/questions/501312/c-multidimensional-collection-to-store-and-retriev.html -> 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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tw1st3d · Jul 31, 2013 at 05:08 PM 0
Share

No, do not use a database. If anything use a .csv file that you could open up and read. I use a .sav file that auto-saves every time you go into a new area, or saves when you tell it to. If you'd like to see what I do, I'd be more than willing to post my code.

avatar image Jokeaccount · Aug 02, 2013 at 12:02 PM 0
Share

If you could post an example just for me to get an idea would be really cool

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Jamora · Jul 31, 2013 at 04:50 PM

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: https://www.assetstore.unity3d.com/#/content/3675 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{
     HealingPotion,
     HolySword,
     ...
 } 

 //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() to get access to all properties all your Items share, or if you need the Sword properties, then use GetComponent()

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image John-LZG · Jan 27, 2014 at 07:05 PM 0
Share

I'd warn caution in using WhyDoIDoIt's save solution. The guy has disappeared for over a year and the save system still has some serious game-breaking bugs that never got worked out. $$anonymous$$aybe if he ever comes back it'll be a good choice again, but for now I'd go with something with an active development.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Database-like arrays 1 Answer

How to make a copy of the data 0 Answers

How to import data into Microsoft Excel? 1 Answer

Data Management Issue - How to manage retrieved data from mysql? 0 Answers

Saving Database from server to local and read from there (android) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges