Search Unity

Creating a custom data layer to a database

Discussion in 'Game Foundation' started by Xystress, Aug 2, 2021.

  1. Xystress

    Xystress

    Joined:
    Sep 19, 2012
    Posts:
    11
    Hi,

    I am starting to work on creating a custom data layer that will connect the game foundation system of our project to a SQL database.

    I am a bit confused: what does the methods Configure, Initialize and the constructor (with the CatalogAsset parameter) should do? Is there any example of implementation ? (I was hopping to check the ChilliConnect implementation but it doesn't seems not included in the package anymore).

    Thanks!
     
    erika_d likes this.
  2. DenariiGames

    DenariiGames

    Joined:
    Dec 29, 2019
    Posts:
    13
    See the skeleton code from Kevin here, substitute your MySQL read writes for the json serialization (or keep that and just use a blob field), profit!
     
    Xystress and erika_d like this.
  3. Xystress

    Xystress

    Joined:
    Sep 19, 2012
    Posts:
    11
    Thank you! It's simpler than I thought. I saw this thread before but the initial post made me think that it was not what I was looking for.

    Cheers!
     
    erika_d likes this.
  4. Xystress

    Xystress

    Joined:
    Sep 19, 2012
    Posts:
    11
    One thing I don't understand in this implementation is when the Save method (from PersistenceDataLayer class) is called. Is it up to the developer to decide, like when the player save the game for instance ?

    Furthermore, the system I am looking for is more for an MMORPG style of game, where the inventory and currencies are updated to the database in realtime. I guess then the PersistenceDataLayer is not what I am looking for?
     
    erika_d likes this.
  5. DenariiGames

    DenariiGames

    Joined:
    Dec 29, 2019
    Posts:
    13
    Saves happen in real-time, on every change to inventory. The main thing you will need to do is:

    1. instantiate the datalayer after the player selected
    2. equip from the inventory on first read, likely on the datalayer initialization success callback

    If you watch my latest devlog video, you'll see that its entirely MMO style.
     
    erika_d likes this.
  6. richj_unity

    richj_unity

    Unity Technologies

    Joined:
    Sep 23, 2019
    Posts:
    40
    The Save method of the PersistenceDataLayer does need to be called by the dev when it's desired, if you want the data to be saved across closing and opening the game. It's not called automatically with each inventory change.

    But if you wrote a custom SQL data layer, then you wouldn't need to call Save because each data layer method could write directly to the SQL database. (Maybe that's what @DenariiGames was saying and I misunderstood.)

    If you want to check out the ChilliConnect adapter example, you can use the Unity 2019 Editor and Package Manager to install Game Foundation version 0.8.0 (in a separate Unity project to be really safe), and the ChilliConnect sample is still there.
     
    erika_d and DenariiGames like this.