- Home /
Unity SQL Database?
I have many variables that need to be stored in player prefs for saving and loading, is it possible to store these variables in a database and then use SQL to call these various variables from the database, then to save the database and the next time the player plays the game it will just recall all the variables from the original database (after they have been edited)
for example if the player is using a sword with +5 damage, I could store that in a database, then the next time the player upgrades his sword to +9 damage I could Update that in the database using (UPDATE tblSwords SET damage = 9) or something along those lines, instead of constantly having to save and load player prefs?? is this possible?
Also I use a $$anonymous$$ac, so what would be a good program to store the database? also is any of this possible? I need it for an iPhone game.
see answer below - but I have to say - a database for what you describe sounds like complete overkill, a lot of extra hassle, and not feature rich enough for some things you'd want. A database isn't really better than player prefs - and saving out playerprefs isn't as much overhead as saving out a database. Also, I would think the best solution would be one that involves serializing a hierarchy of objects that may be nested in interesting ways - like say the player's inventory contained a bag that had a sword in it. With serialized objects, that kind of thing is trivial to represent, but it's very awkward to do with databases.
Thanks for the heads up ^^ I was just considering the database because I have various scenes with objects that the player can place and I need to store the positions of all those objects :/ been using an array so far, going to try a few other things and see how it works
Answer by thorbrian · Nov 22, 2011 at 11:57 PM
You can use the SQLite in Mono if you want - you just need to copy the "Mono.Data.dll", "Mono.Data.Sqlite.dll" and "Mono.Data.SqliteClient.dll" files from "C:\Program Files\Unity\Editor\Data\Mono\lib\mono\2.0" (or whatever is the equivalent dir for you) somewhere under your projects asset folder (don't think it matters where), and then the "Mono.Data.SqliteClient" namespace should be available for use.
Will this work in unity basic? This approach requires plugins
to the person who posted the download: i am an extreme noob to unity, would you $$anonymous$$d making a sample package with the download you created? i would be explosively grateful.
I wonder if anyone knows the answer to that- will this work in Unity basic?
Thanks, $$anonymous$$ike
Answer by busta-gara · Apr 17, 2013 at 08:00 PM
hi, you can use this code its easy to use and its free for your individual use,
use example:
SqliteDatabase sqlDB = new SqliteDatabase(“config.db”);
string query = “INSERT INTO User(UserName) VALUES( ‘Santiago’)”;
sqlDB.ExecuteNonQuery(query);
its so easy… the file “config.db” is necessary exist in the “StreamingAssets” folder
i hate the people who sell this things in the assets store, something easy like this… we need more open sources users :)
link --- > click here to download
link --- > GitHub Repository
works on iOS, MAC OSX, Windows, i dont sure if works on web and android, if you test in that OS tell me the result.. thanks
Hey,
This is working for me on mac.. But when I do this on windows I get DllNotFoundException: sqlite3
Any thoughts?
I Tried Android and Windows. Works really well. One Thing: You NEED to do what the readme says about copying some sqlite3 file to Assets/Plugins/Android
Answer by braidykens29 · May 31, 2013 at 04:35 PM
Apply mssql fix database
Article http://www.sqlserver.fixtoolboxx.com will help you to give the proper understanding about sql databases
Your answer
Follow this Question
Related Questions
Using Unity to connect to a Database 3 Answers
A node in a childnode? 1 Answer
Saving Huge strings over the web 3 Answers
Can't connect from Unity 3.1 to SQL Server Express 8 Answers
using SQL db instead of playerprefs (playerlocation) 0 Answers