Search Unity

Best practices on working with databases

Discussion in 'Getting Started' started by Shargotth, Dec 9, 2021.

  1. Shargotth

    Shargotth

    Joined:
    Apr 28, 2020
    Posts:
    2
    Hi !

    I'm not in the game industry, but I started developing games in my free times. Coming from more "traditional" development environment with a backend and a database server side that is serving a frontend client I'm wondering what is the equivalent here in Unity ?

    Still for fun (not hoping to build the next big game alone) I began to look at developing a multiplayer game. But what is not clear to me is how data are handle ? Are all data being persisted to files and gameObjects ? Or is it possible to plug a database ? If yes what are the best practices when working with a database ? Is their some existing tools ? Are their any drawbacks (latency ?) ?

    Thank you.
     
  2. Oh boy, people are writing entire books on the subjects and we somehow supposed to answer this in a forum post? It's hard. And multiplayer alone is hard, I'm not sure you should start with that.
    In short: in game development, you should aim for the least latency. Which means if you can get away with putting your data in static form into the binary or at least in the package you install with your game somehow, so be it.
    If you write a big MMO where the data is constantly changing and no person should possess the data because what they have they can alter, then you put it on the server somewhere.
    Relational databases are slow like sloths in terms of gaming. There is no way around it. You shouldn't use a database as the data source. You can use them as the source of truth though and cache the data in memory for run-time.
    Minus obviously the slow-operations where speed is less relevant, like registration, log-in, etc.

    So, in short: it depends. And you need to examine every piece of data, look at it critically, evaluate what kind of game you're making and act accordingly.
     
  3. Shargotth

    Shargotth

    Joined:
    Apr 28, 2020
    Posts:
    2
    Hello,

    Thank you for taking the time to answer my question.

    I know this is not an easy subject and I did not expect a straight forward answer but more of a "best practices" or "hint" answer which you did pretty well. Talking about books, do you have any good references to propose ? I already gave a look in the official Unity documentation but I fell I'm not having the answers I'm looking for (or maybe I look at the wrong place).

    I already did a single player game and learn the basics through some tutorial but I admit multiplayer games should not be taken too easily, that's why I try to gatther every piece of information (here it's about data persistence) before getting my hands on it.

    Ok I understand this very well. What could be a good alternative if I still wants to put the data on the server and not on a client? NoSQL database (mongo, couchebase, firebase, ...) ? Key/Value pair stored like redis ? Other ?

    Also, maybe this is out of scope so feel free to not answer it but, I plan to use Mirror as the network API of my project, is their some solution that are easier to integrate with Mirror than others ?

    Thanks for the help.