This will be 2 week that I try to understand how (and even if it’s possible?) to use a database for my project.
I’ve understand that unity doesnt have a “inside” database so i will need to use something else (like a mysql)… but i cant find any tuto/help to help me to do it.
I already have a mysql on a server, but i dont know what to write in my script.
IDbConnection is part of the System.Data.dll, you need to find this dll and drag it into Unity. You can find a version packaged with Mono that comes with Unity in Editor\Data\Mono\lib\mono\2.0
karl.jones → thank a lot! I dont know if it’s me, but i wasnt able to find a way to add a dll to my unity!
larku → yeah, i’ve asked myself many time if a DB was really needed, and yes… (like many many people, i want to make a game… RPG-like, so i guess a DB is a good way to save progression, iventory, skill and a lot of thing…)
Ok, I’ll have to take your word for it, but there are very few situations where this would typically be necessary. Care to share why you’re convinced you need one?
Hum, maybe i’m wrong, but isnt PlayerPrefs just a way to save few data?
I’m plaining to have a lot of thing to keep (like skill, item, player stat…)
During this last week, i’ve found something like this
they say that playerpref is pretty slow… so for a lot of data to store, that’s not good.
And since it’s keep on the player computer, and i would like to try a multiplayer-game, cheating can be easy (maybe?)
on the contrary, here
they say it’s fast and cool…
My little experience told me ‘if something is good and bad, it could be bad for real’… so, i made my mind for a database.
Your solution requires shipping a database with your game and making sure the DB service is running on the player’s machine before the game starts.
Unless you plan for the game to be exclusively online and the player would be required to query a remote database in order to download all of the data for the game. Then if that download fails the game is unplayable.
Like others have said if this is just a single player game then there are much simpler solutions to a database.
What about using xml, you can directly serialize a class into/from xml, its very easy and much preferable to a db. You can even use binary if you prefer and the performance is pretty good. If you want maximum performance then create your own data structure and do the serialising manually but I doubt you need to do this.
I quite a beginner at many level, so every hint are really welcomed, so thank you all!
Indeed, the problem of a external DB is the ‘online only’ (i dont like this), so maybe some xml can be a good idea.
I roughtly now what is xml, but i dont know if it’s worth a mysql DB in term of performance.
If the performane are good, i will give it a look, and maybe use it…
(did someone have a good tuto or something like this?)
But is there risk of cheat (as said, i would like to have a multiplayer, maybe versus part on the game…)? Can someone directly change the xml file or something?
I would say create a class that abstracts the saving away from the rest of the code and then for now implement this with just PlayerPrefs.
If and only if this ever becomes a issue, replace the implementation of that one class to use something that is better/faster/etc.
I’ve used PlayerPrefs on Windows, Linux, iOS, and Android and have never had any issue. It’s not something I’d try and save/read on every frame, but for typical stuff it’s just fine.
I say use PlayerPrefs since it’s just so simple to use, is portable and will take about the same amount of time to implement this with as it took me to write this post
I wouldn’t use PlayerPrefs to save game-specific data. For one thing - it’s a large amount of data potentially. For another - how does it get into a new player’s prefs the first time?
XML files can be imported into the project as TextAssets in which case they’re compiled like any other asset. Not completely cheat proof but nothing really is.
In terms of performance - you should only be loading this data once at the start of your game so honestly it shouldn’t matter much. So your game might take a few extra seconds to load - big deal.
Lastly - you can edit XML (or JSON or whatever) files with notepad. If you have everything in a DB and you want to change how much damage a fireball does then you’re left to write a SQL script to update the row in the DB.
Each to his own. As I stated, I’d start with PlayerPrefs and replace it if it proves an issue (which for me it never has). Spending effort solving hypothetical problems that never eventuate is wasted effort.
I’m not sure what you’re referring to with the ‘how does it get into a new player’s prefs the first time?’ - no pref set? then no prefs yet… Your code could use defaults, or similar, eg:
I’m really glad that some people came for help me and give me hint.
I’ve spent some time looking for xml/json and playerpref, and indead, you where right : It is what i need, far more than a BD!
I still dont know if i will use playerpref or some json… but that a minor issue for the moment.
If you have to store the values in code then why are you saving them to player prefs in the first place? Note that we’re talking about game data not save data
And no - I was making an argument for a runtime serialization of data from flat files
Of course one could always go the ScriptableObject route as well.
What skills, items, and stats a player currently has sure are. What the skills do, item names, and the types of stats and how they affect the player sure aren’t.