0
\$\begingroup\$

I am making a 2d game with Unity, and in my game I want to add a username and a password for each player, so that when the player signs in, they will get all the data about what they played until the moment they signed in (like their highscore and so on)

So my question is: do I need to use a database like sqlite, or could this be done with Unity without needing an external database?

\$\endgroup\$
  • \$\begingroup\$ There are some details missing from your question that would be helpful for creating high-quality answers: 1. what are your target platforms? 2. are these users playing on the same device? 3. if playing on the same device, are they signed into different profiles at the OS level (eg. logging into Windows using their own computer password before running the game)? Please edit your question to clarify these points. \$\endgroup\$ – DMGregory Jul 3 '18 at 15:44
  • \$\begingroup\$ Regarding the title of the question, the fact that the game is 2D is orthogonal to whatever or not it needs a database. We would be more interested in whatever or not this game works over the network, if it is multiplayer, if you need to track the user across multiple devices, what platforms, and of course the kind of data you will be storing. Addendum: whatever you pick, keep all the code to access the database in a single place and use a class or set of classes to encapsulate it, that will make it easier to change it to something else if it turns out you need something different. \$\endgroup\$ – Theraot Jul 3 '18 at 15:50
1
\$\begingroup\$

Definitely do not need a database. You can store this information in a text file, or the PlayerPrefs.

The app would keep a list of player account names and passwords, and when a user tries to log in, search for the combination in the list.

https://docs.unity3d.com/ScriptReference/PlayerPrefs.html

\$\endgroup\$
  • \$\begingroup\$ Even thought different players can sign in with same device ?how can i implement this? And thank u for replying to my questiom \$\endgroup\$ – Nina Jul 3 '18 at 14:36
  • 1
    \$\begingroup\$ If you have this question, there are a lot more basic things about game development and programming you'll have to learn before you can proceed. \$\endgroup\$ – Almo Jul 3 '18 at 14:38
  • \$\begingroup\$ What are the basic things that i need to learn about ? \$\endgroup\$ – Nina Jul 3 '18 at 14:48
  • \$\begingroup\$ If you haven't programmed and completed a game yet, start with something that does not have accounts. Game development is a very hard task, and it takes a whole bunch of different sets of knowledge to assemble the final product. Just that you have "2d games" in your question indicates something about missing knowledge. Why would the dimensionality of the game have anything to do with how accounts are stored? \$\endgroup\$ – Almo Jul 3 '18 at 14:55
  • \$\begingroup\$ Well i am not professional with the game field. I creating this game as a graduation project.and adding accounts and storing them was not something i was planning to do, but it was something that my superviser asked me to do and i dont know how to link this to a game yet \$\endgroup\$ – Nina Jul 3 '18 at 15:10
0
\$\begingroup\$

Are you talking about local user accounts and scoreboards stored on the device? Then an SQL database would likely be overkill. You can store small amounts of data using the PlayerPrefs class. Note that if you want to store passwords (although I am not sure why you would do that for local player profiles) then you should make sure they are properly hashed. The contents of the PlayerPrefs class is stored in plaintext somewhere on the device (where exactly depends on the platform).

If you want global user accounts and scoreboards, then you won't just need a database but also an application server in front of it which prevents people from writing junk into it.

I'm looking forward to playing your game.

\$\endgroup\$
  • \$\begingroup\$ Yes im talking about local user account. Thank you for your answer . It was really helpfull \$\endgroup\$ – Nina Jul 3 '18 at 14:50
0
\$\begingroup\$

it depends of the game, if you will make an online game you should consider use a database to store user data, user credential, achievements, items in inventory, pending quest or complete quests.

of your game wont have online features, then is not recommended, you can use any text file or other formats depending what is better and suits your game like, .json, .yaml, .properties, .INI.

i ussually use .INI files.

\$\endgroup\$
0
\$\begingroup\$

Simple answer to the question as written: Define database.

The minimal viable database accessed from C# is Dictionary, although some may argue that it is List, Array, or Object. These classes can be used from within Unity, and they can be serialized to and from a file on disk.

While we sometimes call libraries like SQLite databases, in reality they are just software libraries. Libraries almost always give you plenty of features you don't need, along with some features you do need, solutions to problems you never knew existed, and generally a lot of correctness. For example, any decent database library doesn't destroy your file if the application crashes while it was still writing to the file.

You could certainly argue either way in your case: use a Dictionary and serialize it to a file (simpler), or use SQLite (likely more correct). Both options are "correct".

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.